簡體   English   中英

Sql 服務器 我們可以在同一個 if 子句中使用多個 OR 和 AND 條件嗎

[英]Sql Server Can we use multiple OR and AND conditions in the same if clause

我在 IF 子句中使用了多個 OR 和 AND 條件,但它拋出錯誤在預期條件的上下文中指定的非布爾類型的表達式,靠近“OR”。

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如果不是null則返回第一個參數,如果第一個參數是null則返回第二個參數。 正如錯誤消息所說,在這種情況下,它不是boolean 如果要檢查 nullibiliy,則需要使用is null運算符:

IF (((@PaidAmount1 IS NULL) OR (@PaidAmount1 = '') OR (@PaidAmount1 = 0.00)) AND 
    ((@PaidAmount2 IS NULL) OR (@PaidAmount2 = '') OR (@PaidAmount2 = 0.00)) AND 
    ((@PaidAmount3 IS NULL) OR (@PaidAmount3 = '') OR (@PaidAmount3 = 0.00)) AND 
    ((@PaidAmount4 IS NULL) OR (@PaidAmount4 = '') OR (@PaidAmount4 = 0.00)))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM