简体   繁体   中英

SSRS Report - IIF statement Question

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)

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

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

Another less elegant way would be to nest your IIF Statements

=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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM