0

In SQL-Server I have a table which contains data like:

----------
ID value
----------
1     p-10
----------
2     p-16
----------
1     p-11
----------
2     p-21
----------
3     p-30
----------

I want to select the data to get output as:

----------
ID    value
----------
1     p-10,p-11
----------
2     p-16,p-21
----------
3     p-30
----------

how can I do this?

richa verma
  • 247
  • 2
  • 13
  • 2
    Have you tried anything yet? What version of SQL Server are you using? – Tim Biegeleisen Mar 02 '20 at 10:40
  • Try this select distinct Country, STUFF((SELECT ',' + (p.City) FROM bdo.TableName AS a where a.Country=b.Country FOR XML PATH(''), TYPE ).value('.', 'NVARCHAR(MAX)') ,1,1,'') AS Cities from bdo.TableName AS b – JonWay Mar 02 '20 at 15:06

0 Answers0