Create a comma separated list from column using select statement
Create a comma-separated list from the column using the select statement: An Overview
Sometimes it is necessary to construct a comma-separated list of column values, such as a list of EmailIDs for mail distribution. In SQL Server, this can be accomplished by using COALESCE, as seen below. Consider using a SQL Server Tutorial or enrolling in a SQL Server Certification Course to gain additional insights and skills.Use of COALESCE to create a comma-separated list
Suppose we have the following data in the 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.
![](https://dotnettrickscloud.blob.core.windows.net/img/sqlserver/commalist.png)
Here I am creating a semicolon(;) separated list. You can use a comma(,) in place of the semicolon to make the comma-separated list.
![](https://dotnettrickscloud.blob.core.windows.net/img/sqlserver/commalist1.png)
For SQL Server database mail setup and configuration and more on how to send mail from SQL Server database you can refer to this article.
Summary
In this article, I expose the use of COALESCE to make comma-separated or deli-meter-separated lists. I hope after reading this article you will know how to configure SQL Database Mail in Sql Server. I would like to have feedback from my blog readers. Please post your feedback, questions, or comments about this article.
FAQs
Q1. In SQL Server, how do I convert a column into a comma-separated list?
Q2. Can I create a comma-separated list without using STRING_AGG()?
Q3. What happens if I wish to exclude NULL values from the comma-separated list?
Q4. What happens if I wish to exclude NULL values from the comma-separated list?
Q5. Is there a maximum amount of values I may concatenate into a comma-separated list?
Take our Sqlserver skill challenge to evaluate yourself!
![](/images/QuizWatch.gif)
In less than 5 minutes, with our skill challenge, you can identify your knowledge gaps and strengths in a given skill.