I need to use conditional ON clause, with the need to place a different column condition in case of if true and in case of if false Here is the example
select a.* b.*
from tblA a inner join tblB b
on a.somefield = b.someOtherField
AND
/*THIS IS WHERE THE PROBLEM STARTS, I am using pseudo code, and need help with the actual code
(
if substring(a.field3, 1,3) <>'' - I want to use substring(a.field3, 1,3)=b.field2
else, I want to use say b.field5='Y'
)
*/
So, effectively in case of IF evaluating to true, I want a select of this kind:
select a.* b.*
from tblA a inner join tblB b
on a.somefield = b.someOtherField
**AND substring(a.field3, 1,3)=b.field2**
And if condition is false, I want the effective join clause to be
select a.* b.*
from tblA a inner join tblB b
on a.somefield = b.someOtherField
**AND b.field5='Y'**
Using SQL Server
Thanks