This question already has an answer here:
- Can I Comma Delimit Multiple Rows Into One Column? [duplicate] 5 answers
I have the following table: tblFile
My Desired output:
I am Concatenating many rows into a single text string; however, I cannot get the grouping correct. As the code is now it will just display for each record in the FileNameString field: AAA,BBB,CCC,DDD,EEE,FFF
Any suggestions with the grouping!
SELECT FileID, Stuff(
(SELECT N', ' + CONVERT(Varchar, FileName)
FROM tblFile FOR XML PATH(''),TYPE )
.value('text()[1]','nvarchar(max)'),1,2,N'')AS FileNameString
From tblFile
GROUP BY FileID