在SQL报表构建器中的SQL表达式中使用多个IIF语句

时间:2019-03-19 11:16:01

标签: sql-server reportbuilder

我要在现有报告中添加一个名为“退款到期”的新列。在本专栏中,我正在为以下逻辑编写表达式:

  1. 如果incurred > 0,则用No

  2. 填充“到期退款”列
  3. 如果incurred =< 0 and status = "closed",则在Yes

  4. 中填充退款列
  5. 如果incurred =< 0 and status does not equal "closed",则在"Refer"

  6. 中填充退款列

我写了以下表达式

=IIF (Fields!GROSS_CLAIMS_INCURRED.Value>"0", "No", IIF(Fields!GROSS_CLAIMS_INCURRED.Value<="0" AND Fields!STATUS.Value="Closed", "Yes", IIF(Fields!GROSS_CLAIMS_INCURRED.Value<="0" AND Fields!STATUS.Value="Open", "Refer", IIF(Fields!GROSS_CLAIMS_INCURRED.Value<="0" AND Fields!STATUS.Value="Reopen", "Refer"))

但是在预览报告时会收到以下错误消息:

  

textrun的Value表达式   ‘Textbox154.Paragraphs [0] .TextRuns [0]”包含错误:[BC30516]   重载解析失败,因为没有可访问的“ IIf”接受   参数数量。

如何解决此问题,或者必须使用哪种表达式才能获得所需的结果?

在此先感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

与嵌套的SWITCH语句相比,

IIF是多个条件表达式的一种更简洁的方法:

=SWITCH(Fields!GROSS_CLAIMS_INCURRED.Value>"0", "No",
Fields!GROSS_CLAIMS_INCURRED.Value<="0" AND Fields!STATUS.Value="Closed", "Yes",
Fields!GROSS_CLAIMS_INCURRED.Value<="0" AND Fields!STATUS.Value="Open", "Refer",
Fields!GROSS_CLAIMS_INCURRED.Value<="0" AND Fields!STATUS.Value="Reopen", "Refer"
)