How To Comma Separated Column name in SQl Server

Question: What is Coalesce Function?

Answer: Coalesce function returns the first non-null expression in the list. If All expressions evaluate to null Value, then the 
Coalesce function will return null value. Ms SQL IsNull function is used to specify how we want to treat NULL  Values. Coalesce return same result as IsNull Function.
 
Question: What is Ltrim Function?

Answer:
 LTRIM to remove leading spaces from a character variable.
 
Step 1: Create A Table.

Create Table Emp(empid numeric(18,0) IDENTITY(1,1) PRIMARY KEY , EmpName varchar(50)).

Step 2:
Insert Data. 
  1.  Insert Into Emp(empName) values('john')  
  2.  Insert Into Emp(empName) values('sachin')  
  3.  Insert Into Emp(empName) values('kamal')  
  4.  Insert Into Emp(empName) values('ram')  
  5.  Insert Into Emp(empName) values('smith')  
  6.  Insert Into Emp(empName) values('gopal')  
Step 3 : See Result.
  1. Select * From Emp  
Result


Step 4:
Comma Separated Value.
  1. Declare @vEmpName varchar(max)  
  2. Select @vEmpName= Coalesce(@vEmpName + ',''') + Ltrim(EmpName) From Emp  
  3.  Print @vEmpName  
Result

 
If useful than please comment.