Du vil bruge FOR XML PATH
konstruere:
SELECT ACCOUNT,
unit,
SUM(state_fee),
Stuff((SELECT ', ' + code
FROM tblmta t2
WHERE t2.ACCOUNT = t1.ACCOUNT
AND t2.unit = t1.unit
AND t2.id = '123'
FOR XML PATH('')), 1, 2, '') [Codes]
FROM tblmta t1
WHERE t1.id = '123'
GROUP BY ACCOUNT,
unit
Se andre eksempler her:
- SQL samme enhed mellem to tabeller skal have ordrenumre i 1 celle
- SQL-forespørgsel for at få aggregerede resultater i kommaseparatorer sammen med gruppe for kolonne i SQL Server