August 25, 2011

COALESCE in SQL Server

I have Employee table and records will look like as below.

image 
One of my colleague raised me a very good question how can we show all employees
with comma separated in a single row.
Like as below.

image 

Yes we can do it we have “COALESCE” in SQL Server.Here is solution

image

If we will see very carefully “COALESCE” is pretty much like CASE expression in SQL.

That’s It
Enjoy Reading.

No comments:

Post a Comment