3

我正在报告 SSRS 报告。我需要为文本框编写一个表达式以显示不同的输入参数(如果提供)。我试过写表达式。但无法做到完美。在这里,我提供了示例代码,其中我需要一个 SSRS 表达式。任何人都可以帮助我以 SSRS 格式提供相同的表达式。

代码

If(Parameters!FromCreationdate.Value !=null && Parameters!ToCreationdate.Value !=null)
{
  "Created Date:"+ Parameters!FromCreationdate.Value + "To Created Date:"+Parameters!ToCreationdate.Value;
}
else if(Parameters!FromCreationdate.Value !=null)
{
  "Created Date:"+ Parameters!FromCreationdate.Value;
}
else if(Parameters!ToCreationdate.Value !=null)
{
 "To Created Date:"+ Parameters!ToCreationdate.Value;
}

表达

=IIf(isnothing(Parameters!FromCreationdate.Value),"", "From Creation Date:"+Parameters!FromCreationdate.Value, iif(isnothing(Parameters!FromCreationdate.Value)),"", "To Creation Date:"+Parameters!FromCreationdate.Value)

谢谢

4

2 回答 2

4

查看表达式示例(报表生成器和 SSRS),更具体地说,请查看SWITCH

当您要测试三个或更多条件时,切换功能很有用。Switch 函数返回与计算结果为 true 的系列中的第一个表达式关联的值

所以你会用它像

=SWITCH(
TEST_CONDITION_1,VALUE_1,
TEST_CONDITION_2,VALUE_2,
TEST_CONDITION_3,VALUE_3,
....
TEST_CONDITION_N,VALUE_N
)
于 2013-07-26T04:48:58.503 回答
2

使用 SWITCH 是一种更好的方法,但是如果由于某种原因您仍然需要/想要嵌套 IIF 语句,则可以改为:

=IIF(Not IsNothing(Parameters!FromCreationdate.Value) And Not IsNothing(Parameters!   ToCreationdate.Value),
    "Created Date: " + Parameters!FromCreationdate.Value +
    " To Created Date: " + Parameters!ToCreationdate.Value,
    IIF( Not IsNothing(Parameters!FromCreationdate.Value),
        "Created Date: " + Parameters!FromCreationdate.Value,
        IIF( Not IsNothing(Parameters!ToCreationdate.Value),
            "To Created Date: " + Parameters!ToCreationdate.Value,
            ""
            )
        )
    )

或者,您也可以这样做:

=IIF( Not IsNothing( Parameters!FromCreationdate.Value ),
    "Created Date: " + Parameters!FromCreationdate.Value,
    "" ) +
IIF( Not IsNothing( Parameters!FromCreationdate.Value ) AND
    Not IsNothing ( Parameters!ToCreationdate.Value ),
    " ", "" ) +
IIF( Not IsNothing( Parameters!ToCreationdate.Value ),
    "To Created Date: " + Parameters!ToCreationdate.Value,
    "" )

如果您在 SSRS 2005 中创建报告并部署到 2008,您可能需要将空字符串 ("") 更改为 Nothing。使用某些导出格式(或者可能是某些浏览器)执行此操作会导致空字符串看起来像当我们在文本字段上设置粗体时,一个破折号。

于 2013-07-26T15:17:09.297 回答