-1

I have a table where an ID has possible multiple values in one column "Name".

This is my table

 -----ID------Name-----
      1       John
      1       Jim 

I what to do this:

 ---- ID ----- Name-----
       1       John, Jim
Joe Doe
  • 159
  • 1
  • 8
  • 1
    This has been asked so many times on SO. Have you had a search or tried anything? Look up `FOR XML PATH ` and `STUFF`, or if you're on the latest version of SQL Server `STRING_AGG`. – Thom A Aug 01 '18 at 12:01

1 Answers1

0

You can try this -

select a.ID,
(select b.Name +', ' from TableName b where b.ID = a.ID FOR XML PATH('')) as Name 
from TableName a
group by a.ID
Aakash Singh
  • 1,032
  • 8
  • 27