Please enable Javascript to correctly display the contents on Dot Net Tricks!

Create a comma separated list from column using select statement

 Print 
  Author : Shailendra Chauhan
Posted On : 23 Aug 2012
Total Views : 135,414   
Updated On : 24 Sep 2016
 

Sometimes we required to generate a comma separated list of columns values like a list of EmailIDs to send mail. In SQL Server, we can make a comma separated list by using COALESCE as shown in below.

Use of COALESCE to create comma separated list

Suppose we have following data in Employee table and we need to make a semicolon separated list of EmailIDs to send mail, then we can use COALESCE as shown in below fig.

Here I am creating a semicolon(;) separated list. You can use comma(,) in place of semicolon to make comma separated list.

For SQL Server database mail setup and configuration and more over how to send mail from SQL Server database you can refer this article.

Summary

In this article I expose the use of COALESCE to make comma separated or deli-meter separated list. I hope after reading this article you will be know how to configure SQL Database Mail in Sql Server. I would like to have feedback from my blog readers. Please post your feedback, question, or comments about this article.



Free Interview Books
 
COMMENTS
18 NOV
Angular with Firebase (Classroom)
04:00 PM-07:00 PM IST(+5:30)
18 NOV
Angular2+4 with Firebase (Online)
10:30 AM-12:30 PM IST(+5.30 GMT)
11 NOV
ASP.NET MVC (Online)
08:00 AM-10:00 AM IST / 09:30 PM To 11:30 PM(CST)
11 NOV
ASP.NET MVC (Classroom)
09:00 AM to 12:00 AM
7 NOV
Developing Microsoft Azure Solutions (Online)
07:00 AM-08:30 AM IST/ 8:30 Pm -10:00 PM CST
14 OCT
Angular2 and Angular4 (Online)
03:00 PM-05:00 PM IST (+5.30GMT)
12 OCT
ASP.NET Core (Online)
09:00 PM - 11:00 PM IST(+5:30 GMT)
10 OCT
Microsoft Azure Infrastructure Solutions (Online)
08:00 AM-09:30 AM IST / 09:30 PM -11:00 PM CST
LIKE US ON FACEBOOK
 
+