设置参数以允许 Null

Setting a parameter to allow Null

I have added a parameter @ConstitID to a SSRS report and when selecting "allow null" I do not get any results unless I uncheck null and enter an integer.

我已经在 Where 子句中尝试了这段代码,但它不起作用。为什么它没有正确使用 NULL

WHERE
  (p_memb_fee_batch_pmt_dst.fee_gl_number IN (@FeeGL_Number))
  AND (p_memb_fee_batch_header.fin_tran_date
     BETWEEN @TransactionDateStart AND @TransactionDateEnd)
  AND (p_memb_fee_batch_payment.constit_id = @ConstitID)
  OR (p_memb_fee_batch_payment.constit_id = NULL)
在 SQL 中的

= NULL 将 return 为假。您需要使用 IS NULL,因此您需要再次检查参数:

WHERE
 (p_memb_fee_batch_pmt_dst.fee_gl_number IN (@FeeGL_Number))
 AND (p_memb_fee_batch_header.fin_tran_date
    BETWEEN @TransactionDateStart AND @TransactionDateEnd)
 AND (p_memb_fee_batch_payment.constit_id = @ConstitID
    OR @ConstitID IS NULL)
 OR (p_memb_fee_batch_payment.constit_id IS NULL)