Rows 2 Cell

Convert items found in a column matching certain material into list in 1 cell separated with comma.
In another word...
Combine values from column into list if they belong to the same item (from another column).

A quick query I needed yesterday, found online from Multiple rows to one comma-separated value

Opposite of Split string into table

Public
Tested
My Own Work
SELECT MaterialNumber ,STUFF((SELECT ', ' + RTrim(CAST(IDENT AS VARCHAR(10))) [text()]
FROM Z_MaterialAllergen
WHERE MaterialNumber = t.MaterialNumber
FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)'),1,2,' ') Allergs
FROM Z_MaterialAllergen t
GROUP BY MaterialNumber

Views 350 Downloads 121

SQL Database
ANmarAmdeen
629
Attachments
Revisions

v2.0