Sunday, November 24, 2013

How to get All "Employee" name field in one row ?

Try the below:



create table test_Nov_25(Empid int, Name varchar(50))

Insert into test_Nov_25 Select 1, 'Amit'
Insert into test_Nov_25 Select 2, 'Krishna'

DECLARE @listStr VARCHAR(MAX) --DO NOT initialize this one!

SELECT @listStr = COALESCE(@listStr + ',' ,'') + nt.Name
FROM test_Nov_25 nt

SELECT @listStr


No comments:

Post a Comment