HOW TO SELECT COMMA SEPARATED LIST IN SQLSERVER

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
 878  View(s)
Ratings:
Rate this:
I want  to select comma separated list in Sql Server please help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: How to View comma separated list from column using select statement In Sqlserver

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!