Pages

Sunday, May 4, 2014

Create a comma separated list from column using select statement

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 delimeter 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.

No comments:

Post a Comment