I have a 1:M recordset that I need to pivot into columns where the results are concatenated.
Create sample data:
CREATE TABLE #temptable
(
ID int,
Division int,
Material int
);
insert into #temptable
Values
(999, 1, 1)
,(999, 1, 2)
,(999, 1, 3)
,(999, 2, 1)
,(999, 2, 6)
,(999, 3, 2)
Sample data:
ID Division Material
---- ---------- ----------
999 1 1
999 1 2
999 1 3
999 2 1
999 2 6
999 3 2
I need the results to look like this, where the materials for each division are concatenated:
ID Division-1 Division-2 Division-3
---- ---------- ---------- ----------
999 1,2,3 1,6 2