我对解决这个问题的最佳方法一无所知。当前查询很好。问题是如果没有返回行,我希望 if 语句为真。我也不想写两次查询,所以我如何以 if 语句为真并运行的方式编写它?
IF (select AnInt from ATable where Cond) = expectedInt
begin ... end
我对解决这个问题的最佳方法一无所知。当前查询很好。问题是如果没有返回行,我希望 if 语句为真。我也不想写两次查询,所以我如何以 if 语句为真并运行的方式编写它?
IF (select AnInt from ATable where Cond) = expectedInt
begin ... end
如果 aNULL
AnInt
不可能,那么您可以使不匹配时的空子选择结果等于expectedInt
IF isnull((select AnInt from ATable where Cond), expectedInt) = expectedInt
像这样?
DECLARE @Test INT
SELECT @Test = AnInt
FROM ATable
WHERE Cond
IF @Test IS NULL OR @Test = expectedInt
BEGIN
...
END
IF Coalesce((select TOP 1 AnInt from ATable where Cond),expectedInt) = expectedInt
begin
end