I have a table that contains several fields, and some of the records are identical except for one of those fields. I'm trying to write a query to return a single row that contains each field plus a combination field representing the concatenated values that were unique to each row.
FIELD1 | FIELD2 | FIELD3 | FIELD4
ROW1 | ABC DEF GHI JKL
ROW2 | ABC DEF GHI MNO
And I want the output to look like:
OUTPUT | ABC DEF GHI JKL,MNO
I can do this in .NET code, but I was hoping to do this in the SQL. Is it possible?
I've found this example, but haven't been able to make it work correctly and don't really understand all of it:
FROM TableParent p
CROSS APPLY (SELECT EMPLOYEENUM + ',' AS [text()]
WHERE ASSIGNNUM =p.ASSIGNNUM
FOR XML PATH(''))el(EmpList)