DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Concate Set Of Rows With Comma (or Any) In A Single String

12.15.2011
| 1508 views |
  • submit to reddit
        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.

<a href="http://www.java-forums.org/blogs/spring-framework/"><strong>Spring Framework</strong></a>