65.9K
CodeProject is changing. Read more.
Home

Concatenate two or more rows with comma (or any you want) in a single string

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.92/5 (13 votes)

Oct 5, 2010

CPOL
viewsIcon

21690

Hi I would like to share cool feature of SQL Server with you guys like: Please use the following query when concatenate two or more rows with comma (or any you want) in a single string.
SELECT STUFF((SELECT ',' + RTRIM(RegionDescription) FROM Region FOR XML PATH('')),1,1,'') AS 'Regions'
This would be also useful when you have to check between condition in SQL Query. Please do let me know, if you have any doubt. Please provide "Vote" if this would be helpful. :rose: