Creating Comma Separated Values List

Kirthiga
Posted by Kirthiga under Sql Server category on | Points: 40 | Views : 1314
DECLARE @Place TABLE([State] varchar(20),Place varchar(20))
insert into @Place values('TamilNadu','Chennai'),('TamilNadu','Trichy'),('TamilNadu','Madurai')
insert into @Place values('Karnataka','Bangalore'),('Karnataka','Goa'),('Karnataka','Mysore')

select * from @Place

select [State],stuff((select ', '+Place from @Place where [State]=a.[State] for xml path('')),1,2,'') Place
from @Place a group by [State]

Comments or Responses

Login to post response