t-sqlms-accessexpressioniif

Expression within IIF in Microsoft Access Expression Builder


I want to perform a calculation if the value in a particular field is greater than zero. Specifically, if the value in Field 1 > 0, I want to calculate the percent total from Fields 2 and 3. (Note I'm using an alias for «Expr», and I've tried it unsuccessfully with and without the space, as well as using «Expr» instead of the alias.

The expression IIf([Field1] >0, Percent Cert: [Field2] / [Field1]) , "N/A") throws a "Too many parameters" error and if I remove the parens around the expression, I get an "invalid syntax" error.

Anyone got any ideas? BTW, I'm perfectly happy to do this in SQL if someone will help me with the syntax.


Solution

  • If Percent Cert is supposed to be the alias field name, it is in wrong position.

    Percent Cert: IIf([Field1] > 0, [Field2] / [Field1], "N/A")

    Or if you want "Percent Cert" as text concatenated to calculated result:

    Some Field Name: IIf([Field1] > 0, "Percent Cert: " & [Field2] / [Field1], "N/A")