Thursday, February 17, 2011

Converting multiple rows into a single comma separated row



Create Table #Names (name varchar(10))

Insert Into #Names(name) values ('varun')
Insert Into #Names(name) values ('vinod')
Insert Into #Names(name) values ('manognya')
Insert Into #Names(name) values ('aradhana')
Insert Into #Names(name) values ('manoj')

SELECT * FROM #Names

SELECT STUFF((SELECT   ', '+  name as [text()] from #Names  FOR  XML PATH('')),1,2,'')

DROP Table #Names




No comments:

Post a Comment