I'd like to fetch values form a table, but the reference is the column name of the destination table instead of a key - yes, bad design. To be honest, I have no clue where to start; could you give me some directions pelase?
Here is what I have
'Source' Table
ID | TargetField
---+-------------
1 | Field1
1 | Field2
2 | Field2
3 | Field1
Rerenced Table:
ID | Field1 | Field2
---+--------+---------
1 | A | B
2 | R | C
3 | X | D
The result would be this:
ID | TargetField | Value
---+-------------+-------
1 | Field1 | A
1 | Field2 | B
2 | Field2 | C
3 | Field1 | X
As said, no idea how to get started... Am I looking at some dynamic SQL?
EDIT: The example is quite simplified, so switch/case will not work for me. I'd like to go for dynamic sql.