30 Jun 2012

SQL SERVER - Comma Separated Values from Table Column using coalesce keyword

Coalesce keyword

Before going to use below script please go run this SQL scripts for creation of tables with data.

Coalesce keyword is useful for fetching first non null value. Using this concept we can make comma separated values from the column.


Declare @output varchar(500)
select @output = coalesce(@output + ', ' , '') + ename FROM employeemaster
print @output 


Output:

ranga, swati, anil, john, Kavitha, padma


This is one of the SQL Server Interview Question.

No comments:

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.