【问题标题】:SSRS - Expression to create string for reporting headingSSRS - 为报告标题创建字符串的表达式
【发布时间】:2015-11-25 10:13:53
【问题描述】:

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

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

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

Benchmark1 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 个参数都不为空,则它不会返回任何错误,并且会填充我希望显示的标题。这怎么可能?

【问题讨论】:

  • 在这种情况下是否使用过BMDataComp2BMDataComp2
  • 通过检查Isnothing()多次使用IIF

标签: reporting-services ssrs-2008 ssrs-2008-r2 ssrs-expression


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

    =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"
    

    无论出于何种原因,它都不喜欢返回“对象引用未设置为对象实例”的 .ToString。通过将其包装在 CStr 中,我能够消除错误并获得所需的解决方案。

    感谢所有回复,他们都提供了帮助。

    【讨论】:

      【解决方案3】:

      这样的东西应该适合你:

      =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")
      

      【讨论】:

      • 感谢您的回复,我收到一条错误消息,提示“对象引用未设置为对象的实例”?我已将@起始参数更改为Parameters!.....,但我看不到错误可能在哪里?
      • 也许这篇文章可以帮助你:social.msdn.microsoft.com/Forums/sqlserver/en-US/…
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多