设置参数以允许Null

时间:2015-03-19 15:39:14

标签: reporting-services

我已将参数@ConstitID添加到SSRS报告中,当选择“allow null”时,除非取消选中null并输入整数,否则我不会得到任何结果。

我在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)

1 个答案:

答案 0 :(得分:1)

SQL中的

= NULL将返回false。您需要使用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)