And优先于
Or,因此,即使
a <=> a1 Or a2
Where a And b
与…不同
Where a1 Or a2 And b,
因为那将被执行为
Where a1 Or (a2 And b)
并且想要使它们相同,是以下内容(使用括号覆盖优先级规则):
Where (a1 Or a2) And b
这是一个示例说明:
Declare @x tinyInt = 1Declare @y tinyInt = 0Declare @z tinyInt = 0Select Case When @x=1 OR @y=1 And @z=1 Then 'T' Else 'F' End -- outputs TSelect Case When (@x=1 OR @y=1) And @z=1 Then 'T' Else 'F' End -- outputs F



