Home > DeveloperSection > Forums > How to select comma separated list in Sqlserver
Ankit Singh

Total Post:341

Points:2389
Posted on    December-25-2015 11:22 PM

 Database SQL Server  SQL  SQL Server 2008  SQL Server 2012 
Ratings:


 1 Reply(s)
 351  View(s)
Rate this:
I want  to select comma separated list in Sql Server please help me.


aditya kumar Patel

Total Post:246

Points:1750
Posted on    December-25-2015 11:28 PM

When we want  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.

declare @strEmailid Varchar(max);

select @strEmailid=COALESCE(@strEmailid+',','')+ EmailID FROM Employee

PRINT @strEmailid


Don't want to miss updates? Please click the below button!

Follow MindStick