It combines all the numers in one unique jobnumber and separate columns per unique orderNM
OLD
jobNumbers orderNM
78506766 0850 0853 2542 9907
78506766 0850 0853 2592
78506766 0851 0853 2542 4801 9907
78506766 0851 0853 2542 9907
78506766 0851 0853 2592
End Result
jobNumbers orderNm1 orderNm2 orderNm3 orderNm4 orderNm5 orderNm6
78506766 0850 0851 0853 2542 4801 9907
select jobNumbers,([1])as orderNm1,[2]as orderNm2,[3]as orderNm2,[4]as orderNm4,[5]as orderNm5,[6]as orderNm6
FROM (select jobNumbers, ordersNUM,
ROW_NUMBER() OVER(
PARTITION BY jobNumbers ORDER BY ordersNUM) as rownum
FROM (SELECT DISTINCT jobNumbers, ordersNUM
FROM orderHistory) AS D1) AS D2
PIVOT(MAX(ordersNUM)
FOR rownum IN([1],[2],[3],[4],[5],[6])) AS P
I've tried this but I can't get to to only put in the single value per column and unique.
OLD
jobNumbers orderNM
78506766 0850 0853 2542 9907
78506766 0850 0853 2592
78506766 0851 0853 2542 4801 9907
78506766 0851 0853 2542 9907
78506766 0851 0853 2592
End Result
jobNumbers orderNm1 orderNm2 orderNm3 orderNm4 orderNm5 orderNm6
78506766 0850 0851 0853 2542 4801 9907
select jobNumbers,([1])as orderNm1,[2]as orderNm2,[3]as orderNm2,[4]as orderNm4,[5]as orderNm5,[6]as orderNm6
FROM (select jobNumbers, ordersNUM,
ROW_NUMBER() OVER(
PARTITION BY jobNumbers ORDER BY ordersNUM) as rownum
FROM (SELECT DISTINCT jobNumbers, ordersNUM
FROM orderHistory) AS D1) AS D2
PIVOT(MAX(ordersNUM)
FOR rownum IN([1],[2],[3],[4],[5],[6])) AS P
I've tried this but I can't get to to only put in the single value per column and unique.