I have the following two tables:
Serial Key Value
ABC Attr1 ABC1
ABC Attr2 ABC2
ABC Attr3 ABC3
XYZ Attr1 XYZ1
XYZ Attr2 XYZ2
XYZ Attr3 XYZ3
and
Key Include IncludeOrder
Attr1 Y 2
Attr2 NULL NULL
Attr3 Y 1
The first table is the data, the second table is the data Key
s to include on the report.
I want to generate the following from a query:
Serial Attr3 Attr1
ABC ABC3 ABC1
XYZ XYZ3 XYZ1
I know this will require a pivot, with a GROUP BY
on Serial
, but I haven't been able to complete the subquery to pull the columns designated by Include
or sort them to be ordered correctly in the output by IncludeOrder
.