我想检查给定的 SubId/WorkflowId 组合是否存在记录ProcessCode = 10
,相同的SubId/WorkflowId
组合有一行ProcessCode
20、30 和 40。下面是我正在尝试做的一个写得很糟糕的版本;我希望有一个更优雅的解决方案。这个查询基本上是在识别任何违反规则的东西。
IF EXISTS( SELECT * FROM @DataTable WHERE SubID = @SubId and WorkflowId = @WorkflowId and ProcessCode = 10)
AND (
NOT EXISTS( SELECT * FROM @DataTable WHERE SubID = @SubId and WorkflowId = @WorkflowId and ProcessCode = 20) or
NOT EXISTS( SELECT * FROM @DataTable WHERE SubId = @SubId and WorkflowId = @WorkflowId and ProcessCode = 30) or
NOT EXISTS( SELECT * FROM @DataTable WHERE SubID = @SubId and WorkflowId = @WorkflowId and ProcessCode = 40)
)