in tsql how can I turn this sample table:
ID FIELDNO ROWNO VALUE
ABC 2 1 Cat1Val1
ABC 2 2 Cat1Val2
ABC 2 3 Cat1Val3
ABC 3 1 Cat2Val1
ABC 3 2 Cat2Val2
ABC 5 1 Cat3Val1
to a table that will create three columns based on the fieldno and duplicate the rows so that it lists all possible variations of whatever fieldno has the highest rowNo?
So fieldno 2 will become CAT1, 3 -> CAT2 and 5 -> CAT3
Expected result:
ID CAT1 CAT2 CAT3
ABC Cat1Val1 Cat2Val1 Cat3Val1
ABC Cat1Val1 Cat2Val2 Cat3Val1
ABC Cat1Val2 Cat2Val1 Cat3Val1
ABC Cat1Val2 Cat2Val2 Cat3Val1
ABC Cat1Val3 Cat2Val1 Cat3Val1
ABC Cat1Val3 Cat2Val2 Cat3Val1
I could then use this as a base to join with other tables.
Here's a fiddle with more data.
I've tried to create some CASE WHEN clauses but I think this is not going to work.
Hope you can show me a way how this can be solved.
Thank you.