I am trying to join a field (in table 1) to table 2 or table 3 depending on the value of a another field in table 1.
My COMM table (1) looks like this:
CommID User ID Type
100 987 SER
101 123 EMP
SER (2) and EMP (3) are tables that will give me information about those Users. I need to join the User ID from the COMM table to teh SER and EMP tables dependent on the Type field in COMMM. This is NOT working but may illustrate what I am trying to do:
select *
CASE WHEN comm.type = 'SER' THEN ser.userName ELSE emp.userName END
FROM COMM
LEFT JOIN SER on SER.userID = comm.UserID and comm.type = 'SER'
LEFT JOIN EMP on EMP.userID = comm.UserID and comm.type = 'EMP'
Any ideas?
My COMM table (1) looks like this:
CommID User ID Type
100 987 SER
101 123 EMP
SER (2) and EMP (3) are tables that will give me information about those Users. I need to join the User ID from the COMM table to teh SER and EMP tables dependent on the Type field in COMMM. This is NOT working but may illustrate what I am trying to do:
select *
CASE WHEN comm.type = 'SER' THEN ser.userName ELSE emp.userName END
FROM COMM
LEFT JOIN SER on SER.userID = comm.UserID and comm.type = 'SER'
LEFT JOIN EMP on EMP.userID = comm.UserID and comm.type = 'EMP'
Any ideas?