There is a table Table1 with rows shown below. Column Label stores priority for column Tag.
Also in column Label - L1 is first priority, L2 is second and L3 is least priority.
I have Value column which holds values for tag and which can be null.
RecordNo. Lable Tag Value
----------------------------------------------
1 L1 T1
2 L2 T1 D12
3 L3 T1 D13
4 L1 T2 D21
5 L2 T2
6 L3 T3
7 L2 T3 D31
8 L2 T4
9 L3 T4 D41
10 L3 T5 D51
I want to write a query to get the output as below.
For every Tag, if value not found for L1 then we will search for L2 and if for L2 data not found then search for L3.So at any point it should return not null value for tag.
Output will look like below.
RecordNo. Lable Tag Value
---------------------------------------------------------
2 L2 T1 D12
4 L1 T2 D21
7 L2 T3 D31
9 L3 T4 D41
10 L3 T5 D51
Can anyone please check on above query?
Thanks in advance.