Data Browser - Viewing Site  Sector 23 Code Bank Logged in as:  Guest  


Sql Server 2008 Comma Delimited List
How to include row values grouped into a comma delimited list in SQL Server 2008: Use the "for xml path" command, and the "stuff" command to remove a trailing comma.

Note: Replace ', ' with ',' and 2 with 1 if you do not want a space after each comma.


Select d.*,
(Select ', ' + cast(s.TextValue as varchar) FROM SomeOtherData s
WHERE s.RefId = d.Id
for xml path('')
), 1, 2, '') TextValueAsList
Data d

Created By: amos 10/3/2012 11:26:01 AM
Updated: 8/12/2015 3:05:14 PM