The following code is used to concatenate many rows into a single text string with comma separated using SQL Server COALESCE
function.
My table format is like this:
Name
RAM
GURU
Sundar
Shyam
Inba
Kalai
I need output like this:
"RAM, GURU, Sundar, Shyam, Inba, Kalai"
I use the following query:
DECLARE @Names VARCHAR(8000)
SELECT @Names = COALESCE(@Names + ', ', '') + Name FROM People
SELECT @Names