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 


ranga, swati, anil, john, Kavitha, padma

This is one of the SQL Server Interview Question.
Share this post :

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.

Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar