Hi there,
Thanks for the last answers. I need some more help, this time with joins. I have 3 tables to join where a case statement is used to change the value in table 1 to RULE value depending on if the value = the value in table 2. But I need to see all the values in table 1 irrespective if the values are the same or not. I am using left joins but only get nulls for values not satisfying the rules.
Thanks
***********************************************************
TABLE1
ID1, NAME, VALUE
----------------
1 bob 3
2 bob 0.1
TABLE2
NAME, VALUE, RULE
-----------------
bob 0.1 1
TABLE3
NAME, UNITS, EL
----------------
bob cm A
***********************************************************
SELECT T1.ID1
, T3.EL + '_' + T3.UNITS AS NAME
, T3.EL
, T3.UNITS
, CASE WHEN T1.NAME = T2.NAME AND T1.VALUE = T2.VALUE THEN cast(T2.RULE AS float) ELSE T1.VALUE END AS VALUE
FROM TABLE T1 LEFT JOIN
TABLE2 T2 ON T1.NAME = T2.NAME AND T1.VALUE = T2.VALUE
LEFT JOIN TABLE3 T3 ON T2.NAME = T3.NAME
Thanks for the last answers. I need some more help, this time with joins. I have 3 tables to join where a case statement is used to change the value in table 1 to RULE value depending on if the value = the value in table 2. But I need to see all the values in table 1 irrespective if the values are the same or not. I am using left joins but only get nulls for values not satisfying the rules.
Thanks
***********************************************************
TABLE1
ID1, NAME, VALUE
----------------
1 bob 3
2 bob 0.1
TABLE2
NAME, VALUE, RULE
-----------------
bob 0.1 1
TABLE3
NAME, UNITS, EL
----------------
bob cm A
***********************************************************
SELECT T1.ID1
, T3.EL + '_' + T3.UNITS AS NAME
, T3.EL
, T3.UNITS
, CASE WHEN T1.NAME = T2.NAME AND T1.VALUE = T2.VALUE THEN cast(T2.RULE AS float) ELSE T1.VALUE END AS VALUE
FROM TABLE T1 LEFT JOIN
TABLE2 T2 ON T1.NAME = T2.NAME AND T1.VALUE = T2.VALUE
LEFT JOIN TABLE3 T3 ON T2.NAME = T3.NAME