June 18, 2014 at 3:43 am
I have the below statement a / b * 10
which way it will execute (a/b)*10 or (a/(b*10))
And also same question for below
WHERE id= @id
AND (typ= 'C'
OR typ= 'H'
AND RID= 1) )
June 18, 2014 at 3:50 am
Multiplication and division have the same precedence, so in the absence of brackets it will be run exactly as written, take a, divide it by b, multiply the result by 10.
With the where clause, AND has precedence over OR, so it will be run as
WHERE id= @id AND (typ= 'C' OR ( typ= 'H' AND RID= 1 ))
If that isn't what you want, use brackets.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply