【发布时间】:2020-06-29 09:35:46
【问题描述】:
我在 IF 子句中使用了多个 OR 和 AND 条件,但它抛出错误 在预期条件的上下文中指定的非布尔类型表达式,靠近“或”。
DECLARE @PaidAmount1 DECIMAL(18, 2);
DECLARE @PaidAmount2 DECIMAL(18, 2);
DECLARE @PaidAmount3 DECIMAL(18, 2);
DECLARE @PaidAmount4 DECIMAL(18, 2);
IF(((ISNULL(@PaidAmount1,'')) OR (@PaidAmount1='') OR (@PaidAmount1=0.00)) AND ((ISNULL(@PaidAmount2,'')) OR (@PaidAmount2='') OR (@PaidAmount2=0.00)) AND ((ISNULL(@PaidAmount3,'')) OR (@PaidAmount3='') OR (@PaidAmount3=0.00)) AND ((ISNULL(@PaidAmount4,'')) OR (@PaidAmount4='') OR (@PaidAmount4=0.00)))
BEGIN
--statements goes here
END
我们可以像上面那样使用 OR 和 AND 条件吗?
谢谢! 夏姆
【问题讨论】:
-
((ISNULL(@PaidAmount1,''))不是布尔表达式 -
另外,你的变量是小数,为什么要把它们和空字符串比较?
-
使用这样的东西 ((ISNULL(@PaidAmount1,'')='') 或 @PaidAmount1 IS NULL
-
HoneyBadger 和 NP007 你说的是对的。十进制不接受字符串。
标签: sql-server toad