SSRS - 为报告标题创建字符串的表达式

SSRS - Expression to create string for reporting heading

我有一份报告,其中包含 6 个参数。我想做的是将这些参数作为我的报告标题的一部分。我的参数如下:

@BMDataType1  Text
@BMDataComp1  Float
@BMDataType2  Text
@BMDataComp2  Float
@BMDataType3  Text
@BMDataComp3  Float

总会有一个@BMDataType1 和@BMDataComp1 参数传递,其他可以为空。我需要的标题看起来像如果只传递@BMDataType1 和@BMdataComp1 那么标题应该是例如:

基准 1 100% 基准成分股

到目前为止,我已经为此编写了以下代码:

=Parameters!BMDataType1.Value + " " + Parameters!BMDataComp1.Value.ToString + "%" + " Benchmark Constituents"

但是,如果填充了@BMDataType2 和@BMDataComp2,那么我需要这样的标题:

基准 1 50% 基准 2 50% 基准成份股

如果通过 3 则相同:

基准 1 50% 基准 2 30% 基准 3 20% 基准成份股

永远不会说基准 1 和基准 3。它只会是 1,或 1 和 2,或 1、2 和 3。

有人能告诉我如何编写 IIF 语句以检查 Benchmark2 和 Benchmark3 参数是否为 NULL 的正确方向吗?

谢谢

编辑:

经过一些工作后,我想出了以下代码,但我仍然得到:

"Object reference not set to an instance of an object"

我的代码如下:

=IIF(
    IIF(IsNothing(Parameters!BMDataType1.Value),1,0)=0 AND IIF(IsNothing(Parameters!BMDataType2.Value),1,0)=1 AND IIF(IsNothing(Parameters!BMDataType3.Value),1,0)=1
,   Parameters!BMDataType1.Value + " " + Parameters!BMDataComp1.Value.ToString + "%" + " Benchmark Constituents"
, IIF(
    IIF(IsNothing(Parameters!BMDataType1.Value),1,0)=0 AND IIF(IsNothing(Parameters!BMDataType2.Value),1,0)=0 AND IIF(IsNothing(Parameters!BMDataType3.Value),1,0)=1
,   Parameters!BMDataType1.Value + " " + Parameters!BMDataComp1.Value.ToString + "%" + " " + Parameters!BMDataType2.Value + " " + Parameters!BMDataComp2.Value.ToString + "%" + " Benchmark Constituents"
, IIF(
    IIF(IsNothing(Parameters!BMDataType1.Value),1,0)=0 AND IIF(IsNothing(Parameters!BMDataType2.Value),1,0)=0 AND IIF(IsNothing(Parameters!BMDataType3.Value),1,0)=0
,   Parameters!BMDataType1.Value + " " + Parameters!BMDataComp1.Value.ToString + "%" + " " + Parameters!BMDataType2.Value + " " + Parameters!BMDataComp2.Value.ToString + "%" + " " + Parameters!BMDataType3.Value + " " + Parameters!BMDataComp3.Value.ToString + "%" + " Benchmark Constituents"
, " ")))

但是,如果所有 3 个参数都不为空,它 returns 没有错误,它会填充我希望显示的标题。怎么会这样?

像这样的东西应该适合你:

=Parameters!BMDataType1.Value + " " + Parameters!BMDataComp1.Value.ToString + "%" + IIf(IsNothing(Parameters!BMDataType3.Value) OR IsNothing(Parameters!BMDataComp3.Value), IIf(IsNothing(Parameters!BMDataType2.Value) OR IsNothing(Parameters!BMDataComp2.Value), " Benchmark Constituents", " " + Parameters!BMDataType2.Value + " " + Parameters!BMDataComp2.Value.ToString + "%" + " Benchmark Constituents"), " " + Parameters!BMDataType2.Value + " " + Parameters!BMDataComp2.Value.ToString + "%" + " " + Parameters!BMDataType3.Value + " " + Parameters!BMDataComp3.Value.ToString + "%" + " Benchmark Constituents")

自 5 月以来我就没有使用过 SSRS,但 SSRS 中的字符串连接使用 VB 语法。因此,您必须使用 & 符号而不是使用 + 符号连接字符串。

=Parameters!BMDataType1.Value & " " & Parameters!BMDataComp1.Value.ToString & "%" & " Benchmark Constituents"

我找到了解决方法,我的代码如下:

=Parameters!BMDataType1.Value + " " + CStr(Parameters!BMDataComp1.Value) + "% " 
+ IIF(IIF(IsNothing(Parameters!BMDataType2.Value),1,0)=0,Parameters!BMDataType2.Value + " " + CStr(Parameters!BMDataComp2.Value)+"%","") + " "
+ IIF(IIF(IsNothing(Parameters!BMDataType3.Value),1,0)=0,Parameters!BMDataType3.Value + " " + CStr(Parameters!BMDataComp3.Value)+"%","") + " Benchmark Constituents"

无论出于何种原因,它不喜欢返回 "Oject reference not set to an instance of an object" 的 .ToString。通过将其包装在 CStr 中,我能够消除错误并获得所需的解决方案。

感谢大家的回复,他们都很有帮助。