测试所有行都存在

pdu*_*usp 3 sql exists

测试行是否存在非常简单.

if exists(select * from dbo.APQP_head where zestaw=@zestaw)
Run Code Online (Sandbox Code Playgroud)

我想在我的查询中测试是否所有行都满足条件.

我需要使用这样的一些查询

if All exists(select * from dbo.APQP_head where zestaw=@zestaw and type=3)
Run Code Online (Sandbox Code Playgroud)

但是这种语法不正确.

Ole*_*Dok 6

if NOT exists(select * from dbo.APQP_head where zestaw<>@zestaw OR type<>3) 
  --all rows satisfy the condition
Run Code Online (Sandbox Code Playgroud)

如果您的列可以为空,那么

if NOT exists(select * from dbo.APQP_head where zestaw<>@zestaw OR type<>3) 
AND NOT exists(select * from dbo.APQP_head where zestaw IS NULL OR type IS NULL) 
Run Code Online (Sandbox Code Playgroud)