In the following I need to link 'clientlink' to another table - ar.client to pull names and other fields. Since 'clientlink' is controled by the case statement, is a link possible here, or should this be a 2 step process where the second step links these results to the client table?
select clientlink = case sc.instrument_i
when 43 then youth.clientid_c
when 44 then parent.clientid_c
when 45 then worker.clientid_c
else '999999999'
end,
sc.*
from cd.bhosscore sc
left join cd.episode457 youth on sc.linkid_c = youth.uniqueid_c and sc.instrument_i = 43
left join cd.episode458 parent on sc.linkid_c = parent.uniqueid_c and sc.instrument_i = 44
left join cd.episode459 worker on sc.linkid_c = worker.uniqueid_c and sc.instrument_i = 45
Thanks, Paul
select clientlink = case sc.instrument_i
when 43 then youth.clientid_c
when 44 then parent.clientid_c
when 45 then worker.clientid_c
else '999999999'
end,
sc.*
from cd.bhosscore sc
left join cd.episode457 youth on sc.linkid_c = youth.uniqueid_c and sc.instrument_i = 43
left join cd.episode458 parent on sc.linkid_c = parent.uniqueid_c and sc.instrument_i = 44
left join cd.episode459 worker on sc.linkid_c = worker.uniqueid_c and sc.instrument_i = 45
Thanks, Paul