首页 > 代码库 > Grouping by Multiple Columns to Single Column as A String

Grouping by Multiple Columns to Single Column as A String

 

SELECT t.PROB_ID, STUFF(
(SELECT ‘,‘ + s.NOTES
FROM gpcomp1.GPPROBNOTES s
WHERE s.PROB_ID = t.PROB_ID
FOR XML PATH(‘‘)),1,1,‘‘) AS NOTES
FROM gpcomp1.GPPROBNOTES AS t
GROUP BY t.PROB_ID