I'm looking at the following link:
Can I Comma Delimit Multiple Rows Into One Column?
The query used in the solution is exactly what I need, but also need to return NULL values.
SELECT t.TicketID,
STUFF(ISNULL((SELECT ', ' + x.Person
FROM @Tickets x
WHERE x.TicketID = t.TicketID
GROUP BY x.Person
FOR XML PATH (''), TYPE).value('.','VARCHAR(max)'), ''), 1, 2, '') [No Preceeding Comma]
FROM @Tickets t
GROUP BY t.TicketID
This works great if each [TicketID] has an associated [Person].
But if the Person is NULL, for the TicketID, I need to return just the TicketID and have the Person show as NULL or blank. I'm having trouble removing the ISNULL cleanly.
From this:
[TicketID], [Person]
T0001 Alice
T0001 Bob
T0002 Catherine
T0002 Doug
T0003 Elaine
T0004 NULL
To this:
[TicketID], [Person]
T0001 Alice, Bob
T0002 Catherine, Doug
T0003 Elaine
T0004 NULL