Ok so I have a table of components and a colleague needs some data from this table in a different format, now I could do it with some python or java code but wondered if there is a simpler way in MS-SQL with a PIVOT maybe?
Components Table:-
ID_RECIPE COMPONENT QTY
1 CPA 1.00
1 CPC 0.50
2 CPA 10.0
2 CPF 7.50
2 CPH 3.00
2 CPJ 2.25
2 CPP 0.25
There is never more than 5 components to a recipe so I want to be able to output something like this:-
ID_RECIPE COMP_1 COMP_2 COMP_3 COMP_4 COMP_5 QTY_1 QTY_2 QTY_3 QTY_4 QTY_5
1 CPA CPC NULL NULL NULL 1.00 0.50 NULL NULL NULL
2 CPA CPF CPH CPJ CPP 10.00 7.50 3.00 2.25 0.25
Any ideas would be appreciated.