I am trying to create a select statement to combine values from duplicated IDs on any specific columns.
My table is:
ID Name
---------
01 A
01 B
02 C
03 D
How can I select to get values like: 01 A, B for ID: 01. Currently, when I use Select * from Tablename, it lists 01 ID for two rows. I like to combine it into one row only, Name should be combined with a comma for any duplicated rows.
New code:
select Name, ID = REPLACE
((select Surname AS [data()]
FROM Mytable
WHERE Name = d. Name
ORDER BY Name FOR XML path('')), ' ', REQUIRED SEPERATOR)
FROM Mytable d
WHERE Name IS NOT NULL
GROUP BY Name
Thank you very much!