SQL SSRS 报告 - IIF 声明问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4879706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 09:10:06  来源:igfitidea点击:

SSRS Report - IIF statement Question

sqlif-statementssrs-2008reporting-services

提问by GabrielVa

Doing an expression I get an error, can someone show me the correct syntax here?

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

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

回答by Joel Beckham

If you want this to all be in one expression, you may want to use the SWITCH statement:

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

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

The switch statement will return the value for the first condition that is true.Using your example, you could try:

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...)

回答by mr.theTrain

Another less elegant way would be to nest your IIF Statements

另一种不太优雅的方法是嵌套您的 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))))))))))

You could also do your logic in the query:

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

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