converting ID to column name and also replacing NULL with last known value.
- by stackoverflowuser
TABLE_A
Rev ChangedBy
-----------------------------
1 A
2 B
3 C
TABLE_B
Rev Words ID
----------------------------
1 description_1 52
1 history_1 54
2 description_2 52
3 history_2 54
Words column datatype is ntext.
TABLE_C
ID Name
-----------------------------
52 Description
54 History
OUTPUT
Rev ChangedBy Description History
------------------------------------------------
1 A description_1 history_1
2 B description_2 history_1
3 C description_2 history_2
Description and History column will have the previous known values if they dont have value for that Rev no. i.e. Since for Rev no. 3 Description does not have an entry in TABLE_B hence the last known value description_2 appears in that column for Rev no. 3 in the output.