I have the following data in a mapping table:
ID1 LOCALID ID2
Local_-1 BankA_7-9 Local_2647
Local_0 Bank_7-9 Local_2647
Local_2624 BGROMF NULL
Local_2619 BIS NULL
ID2 is nullable.
My second table looks like:
ID1 ID2
Local_-1 Local_2674
Local_0 Local_2674
Local_2624 Local_2674
Local_2619 Local_2674
How do I inner join the tables with the following condition? Is it possible to do this without an if statement?
If ID2 in the mapping table is null just join on ID1 otherwise join on ID1 and ID2.
My starting point (which will obviously exclude the null values) is:
SELECT * FROM
#Table2 C
INNER JOIN Mapping F
ON C.ID1 = F.ID1 AND
C.ID2 = F.ID2
1 Answer