I am trying to use a case statement in my join. I have two tables A and B which need to be joined to either table C or table D depending on the type column in table A. Can this be done by joining using a case statement? I haven't been able to get past a missing keyword error. The code is as follows.
From WTM_STG_POLICY P
LEFT JOIN WTM_STG_CLIENT C on substr(P.POL_IDX,1,7) = C.Rec
LEFT JOIN
CASE
WHEN WTM_STG_POLICY.TYPE = 'AUTO' THEN
WTM_STG_AP2DBF D2 on substr(P.POL_IDX,1,7) = substr(D2.REC,1,7)
else
WTM_STG_AP3DBF D3 on substr(P.POL_IDX,1,7) = substr(D3.REC,1,7)
end
From WTM_STG_POLICY P
LEFT JOIN WTM_STG_CLIENT C on substr(P.POL_IDX,1,7) = C.Rec
LEFT JOIN
CASE
WHEN WTM_STG_POLICY.TYPE = 'AUTO' THEN
WTM_STG_AP2DBF D2 on substr(P.POL_IDX,1,7) = substr(D2.REC,1,7)
else
WTM_STG_AP3DBF D3 on substr(P.POL_IDX,1,7) = substr(D3.REC,1,7)
end