Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I am working on an if condition and questioning how it is working:
if(x=1 and y=0 or y= null(),'yes','no') as test
is it (1st condition must be valid AND 2nd condition must be valid) OR 3rd condition must be valid (only)
vs
1st condition must be valid AND (2nd condition must be valid OR 3rd condition must be valid) ?
If it is working like described in the second mode, I would need to rewrite my if statement to
if(x=1 and y=0 or x=1 and y= null(),'yes','no') as test2
Thanks for sharing your insights.
When more than one logical operator is used in a condition, NOT is evaluated first, then AND, and finally OR. The best way to straighten this so there no confusion is to group the logical bulks with parentheses.
if(x=1 and (y=0 or y= null() ),'yes','no') as test
In your case I would also recommend to switch the y=null() with isnull(y) like this
if(x=1 and( y=0 or isnull(y)) ,'yes','no') as test