Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / SQL

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

4.92/5 (14 votes)
4 Oct 2010CPOL 21.7K  
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.
SQL
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:

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)