How to get column values as comma separated string in SQL

Ever wondered that how to get a comma (pipe or whatever) separated result for a column in a table in SQL Server?

The following statement show a simple example you can take as a starting point.


Select (Stuff((Select ', ' + FName From Accounts FOR XML PATH('')),1,2,''))

Update: Elina Blank suggested an alternative to the approach above on my CodeProject Tip. Thanks Elina 🙂

Have a look at alternative here at CodeProject.