Paddling in the murky bits of the byte stream
Friday, May 28, 2010
Concatenating String Fields In T-SQL
Lets say you've got a table called 'metaproperty' with an NVARCHAR(50) field called 'names'. How do you get all the values of the 'names' field concatenated into one string, separated by commas?
(SELECT N',' + names
FROM (SELECT * FROM metaproperty) AS Y
--ORDER BY names
FOR XML PATH('')),
1, 1, N'')
The ORDER BY is optional, as are any DISTINCTs you might want to shove in...
Post a Comment
Post Comments (Atom)