'Conditional join SQL Server with condition

I have tree tables like this: inserir a descrição da imagem aqui

I need to do this join enter image description here

Select * from table A lef join table B on A.A=B.A

left join table C on ***if*** C.col2= 1 then B.B=C.B if C.col2=0 then B.C=C.C

Is there any way to create the last join as a conditional join without became the query slow?

Thanks

sql


Solution 1:[1]

Using join with AND condition would work.

Select * from table A left join table B on A.A=B.A

left join table C on B.B=C.B and C.col2= 1

OR B.C=C.C and C.col2=0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abeera Shahbaz