I'm looking to pivot my key-value pairs from two tables into a pivoted view. In my example below, I'm showing 5 of the Key records and their values from the data table. I do, in fact, have over 600 of the Key records and various views and reports will need to be created from certain Key fields in the Definition table, so I will be expanding whatever answers I can get here into a more complex query. For now, though, I just need to display data.
I have the following data:
OrderDefinition
Table:
OrderDefsID OrderDefName
--------------------------------------
1 diam_aim
2 len_aim
3 len_htol
4 len_ltol
5 wgt_aim
OrderData
table:
OrderHeaderID OrderDefID OrderDefValue
---------------------------------------------------
1 1 13.000
1 2 8.00
1 3 8.84
1 4 8.44
1 5 3611
2 1 13.000
2 2 7.98
2 3 8.43
2 4 7.32
2 5 3601
3 1 10.000
3 2 7.93
3 3 8.03
3 4 4.48
3 5 2115
What I would like to see is this:
OrderHeaderID diam_aim len_aim len_htol len_ltol wgt_aim
--------------------------------------------------------------------------
1 13.000 8.00 8.84 8.44 3611
2 13.000 7.98 8.43 7.32 3601
3 10.000 7.93 8.03 4.48 2115
I have looked around for examples to learn from, but I can find very little dynamic examples that include a join. I don't want to do any math at all, just display the data by pivoting it and list the Key-Value pairs by OrderHeaderID
.
I'm thinking this will require a Pivot, but if anyone knows another method, I'd love to learn it.