2011-07-29 127 views
1

我需要我的最終決定字段是IIF聲明的結果。訪問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; 

回答

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; 
+0

謝謝!!該死的,我知道這很簡單,然後我想! –

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;