Search code examples
ms-accessiifiif-function

Access IIF Query


I need my Final Decision field to be the result of the IIF statement.

But I keep getting syntax errors.

    SELECT x.AR_ID, 
           Final Decision: IIf([x].[R_DECISION] Is Not Null,
                               [R_DECISION],
                               IIf([ap_decsion] Is Not Null,
                                   [ap_decsion],
                                   IIf([ho_decision] Is Not Null,
                                       [ho_decision],[ar_decision])
                                   )
                              ) FROM x;

Solution

  • You need to put the column alias at the end of the IIF statement and put [] around it

      SELECT x.AR_ID, 
             IIf([x].[R_DECISION] Is Not Null,
                [R_DECISION],
                IIf([ap_decsion] Is Not Null,
                   [ap_decsion],
                      IIf([ho_decision] Is Not Null,
                         [ho_decision],
                         [ar_decision]))) as [Final Decision:]
    
      FROM x;