SQL Server ANDs and ORs precedence [duplicate]

人盡茶涼 提交于 2020-01-03 18:32:09

问题


I'm debugging some code and came across this. Could someone help me by putting parens around this statement according to SQL Server ordering. Is it just me, or is this bad coding?

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

回答1:


As is, it will be parsed like

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


来源:https://stackoverflow.com/questions/17094612/sql-server-ands-and-ors-precedence

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!