【问题标题】:SSRS Report - IIF statement QuestionSSRS 报告 - IIF 声明问题
【发布时间】:2011-02-02 20:52:14
【问题描述】:

做一个表达式我得到一个错误,有人可以在这里告诉我正确的语法吗?

=IIf(Fields!t_cpcp.Value ="310", "Purchased Material & Raw Material", Nothing)
=IIf(Fields!t_cpcp.Value ="320", "Manufacturing Direct Labor", Nothing)
=IIf(Fields!t_cpcp.Value ="325", "Subcontract Cost", Nothing)
=IIf(Fields!t_cpcp.Value ="330", "Engineering Direct Labor", Nothing)
=IIf(Fields!t_cpcp.Value ="340", "Manufacturing Labor O/H", Nothing)
=IIf(Fields!t_cpcp.Value ="345", "Engineering Labor O/H", Nothing)
=IIf(Fields!t_cpcp.Value ="350", "Material O/H", Nothing)
=IIf(Fields!t_cpcp.Value ="355", "Labor O/H Surcharge", Nothing)
=IIf(Fields!t_cpcp.Value ="360", "Subcontract Material Burden", Nothing)
=IIf(Fields!t_cpcp.Value ="MFD", "Manufactured Items", Nothing)

【问题讨论】:

  • 有机会告诉我们错误是什么吗?
  • 是一个表达式还是多个表达式?,因为您显示的表达式不止一个
  • 嗯,我有一列返回一个值,并且基于该值,我希望表达式列显示上面查询中的值之一。所以它是一个。
  • 我得到的错误是 BC30205,预期语句结束。但我认为总体上是错误的,不确定。
  • 您需要 switch 语句或嵌套 iif 语句。

标签: sql if-statement ssrs-2008 reporting-services


【解决方案1】:

如果您希望这一切都在一个表达式中,您可能需要使用 SWITCH 语句:

=Switch(<condition>, <return value if true>, <next condition>, <return value if true>, ...)

switch 语句将返回第一个条件为真的值。使用您的示例,您可以尝试:

=Switch(Fields!t_cpcp.Value ="310", "Purchased Material & Raw Material",
        Fields!t_cpcp.Value ="320", "Manufacturing Direct Labor",
        Fields!t_cpcp.Value ="325", "Subcontract Cost",
        ...rest of them go here...)

【讨论】:

    【解决方案2】:

    另一种不太优雅的方法是嵌套 IIF 语句

    =IIf(Fields!t_cpcp.Value ="310", "Purchased Material & Raw Material",IIf(Fields!t_cpcp.Value ="320", "Manufacturing Direct Labor",IIf(Fields!t_cpcp.Value ="325", "Subcontract Cost",IIf(Fields!t_cpcp.Value ="330", "Engineering Direct Labor",IIf(Fields!t_cpcp.Value ="340", "Manufacturing Labor O/H",IIf(Fields!t_cpcp.Value ="345", "Engineering Labor O/H",IIf(Fields!t_cpcp.Value ="350", "Material O/H",IIf(Fields!t_cpcp.Value ="355", "Labor O/H Surcharge",IIf(Fields!t_cpcp.Value ="360", "Subcontract Material Burden",IIf(Fields!t_cpcp.Value ="MFD", "Manufactured Items", Nothing))))))))))
    

    您也可以在查询中执行您的逻辑:

    CASE t_cpcp WHEN '310' THEN 'Purchased Material & Raw Material'
                WHEN '320' THEN 'Manufacturing Direct Labor'
                WHEN  ...    THEN ....
                ELSE ''
    END as t_cpcp_DESC
    

    【讨论】:

      猜你喜欢
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 2014-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-11
      相关资源
      最近更新 更多