SQL Server AND和OR优先级

时间:2013-06-13 18:39:46

标签: sql-server operator-precedence

我正在调试一些代码并遇到了这个问题。根据SQL Server的命令,有人可以通过在这个语句周围添加parens来帮助我。它只是我,还是这个糟糕的编码?

WHERE 
T1.C1 = @VAR1 AND T1.C2 = @VAR2 AND T1.C3 NOT IN(@VAR3)
OR T2.C1 = @VAR2 OR T3.C1 = @VAR2

1 个答案:

答案 0 :(得分:5)

原样,它将被解析为

WHERE 
(T1.C1 = @VAR1 AND T1.C2 = @VAR2 AND T1.C3 NOT IN(@VAR3))
OR
(T2.C1 = @VAR2)
OR
(T3.C1 = @VAR2)