我正在报告SSRS报告。我需要为Textbox编写一个表达式,以显示不同的输入参数(如果提供)。我试过写表达式。但无法使其完美。在这里,我提供了示例代码,我需要有一个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)
由于
答案 0 :(得分:4)
查看Expression Examples (Report Builder and SSRS),更具体地说,请查看SWITCH
当您有三个或更多条件时,Switch功能非常有用 去测试。 Switch函数返回与之关联的值 在系列中的第一个表达式,其值为true
所以你会使用类似
的东西=SWITCH(
TEST_CONDITION_1,VALUE_1,
TEST_CONDITION_2,VALUE_2,
TEST_CONDITION_3,VALUE_3,
....
TEST_CONDITION_N,VALUE_N
)
答案 1 :(得分: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。使用某些导出格式(或可能是某些浏览器)执行此操作会导致空字符串当我们在文本字段中设置了粗体时,看起来像一个破折号。