Share

GROUP BY clause to get comma-separated values


How to GROUP BY clause to get comma-separated values in SQL server

SELECT ContainerID, DataExportTypeID =
STUFF((SELECT ", " + CONVERT(nvarchar(50), DataExportTypeID)
FROM dbo.DocumentContainerExport b
WHERE b.ContainerID = a.ContainerID
FOR XML PATH("")), 1, 2, "")
FROM dbo.DocumentContainerExport a
GROUP BY ContainerID

1