Skip to content
Advertisement

Conditional Inner Join with two Functions

I have two functions. I need to decide whether to join with these two based on a BIT Value.

Basically

if BIT=0 join with function 1 else join with function 2

I tried putting an IF Clause .. but it does not seem to work. What is the proper way to do it?

Advertisement

Answer

Just add your static condition as part of the join condition and use a LEFT JOIN to ensure it works with the missing row. You can then use a case expression in your select to obtain the correct column e.g.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement