SELECT DISTINCT t.[Item#],
(SELECT TOP 1 'Color: ' + t1.[Color] + CHAR(10) + 'Ink: ' + t1.Ink
FROM SomeTable t1
WHERE t1.[Item#] = t.[Item#] AND t1.Sequence = 1) AS Station1,
(SELECT TOP 1 'Color: ' + t2.[Color] + CHAR(10) + 'Ink: ' + t2.Ink
FROM SomeTable t2
WHERE t2.[Item#] = t.[Item#] AND t1.Sequence = 2) AS Station2,
(SELECT TOP 1 'Color: ' + t3.[Color] + CHAR(10) + 'Ink: ' + t3.Ink
FROM SomeTable t3
WHERE t3.[Item#] = t.[Item#] AND t3.Sequence = 1) AS Station3,
... you get the idea :)
(SELECT TOP 1 'Color: ' + t15.[Color] + CHAR(10) + 'Ink: ' + t15.Ink
FROM SomeTable t15
WHERE t15.[Item#] = t.[Item#] AND t1.Sequence = 15) AS Station15
FROM SomeTable t
FamousMortimer
ASKER
First of all, thanks a lot, this works but...
Is there no way to do it using the pivot function or a more efficient way?
Right now it's not that bad, it takes about 3-4 seconds but the table currently only has 30k rows and grows by up to several hundred per day.