converting ID to column name and also replacing NULL with last known value.

Posted by stackoverflowuser on Stack Overflow See other posts from Stack Overflow or by stackoverflowuser
Published on 2010-03-04T19:26:17Z Indexed on 2010/05/17 3:00 UTC
Read the original article Hit count: 189

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server