Hi

Concatenate many rows into a single text string using SQL Server 2008

Using COALESCE function - concatenate many rows into a single text string output in SQL Server.
The following code is used to concatenate many rows into a single text string with comma separated using SQL Server COALESCE function.(follwing two examples)



1.  DECLARE @Names VARCHAR(8000)
     SELECT @Names = COALESCE(@Names + ', ', '') + Email FROM Emp_tb_eob_Employee             where EmployeeID in(12,1)
     SELECT @Names

2.
Previous
Next Post »