访问IIF查询

时间:2011-07-29 13:40:00

标签: ms-access iif iif-function

我需要我的最终决定字段是IIF声明的结果。

但我一直在收到语法错误。

    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;

2 个答案:

答案 0 :(得分:1)

您需要将列别名放在IIF语句的末尾,并将[]放在其周围

  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;

答案 1 :(得分:0)

请尝试使用ISNULL:

SELECT x.AR_ID, Final Decision: IIf(NOT ISNULL([x].[R_DECISION]),[R_DECISION],IIf(NOT ISNULL([ap_decsion]),[ap_decsion],IIf(NOT ISNULL([ho_decision]),[ho_decision],[ar_decision]))) FROM x;