I have a requirement where my current table has
id value
1 newyork
1 boston
1 dallas
I need the following output
id value
1 newyork, boston, dallas
I have a requirement where my current table has
id value
1 newyork
1 boston
1 dallas
I need the following output
id value
1 newyork, boston, dallas
Declare @YourTable table(ID int,[value] varchar(50))
Insert Into @YourTable values
(1,'newyork'),
(1,'boston'),
(1,'dallas')
Select A.ID
,Value = (Select Stuff((Select Distinct ',' +value From @YourTable Where ID=A.ID For XML Path ('')),1,1,'') )
From (Select Distinct ID From @YourTable) A
Returns
ID Value
1 boston,dallas,newyork