2016-06-08 110 views
0

我很多orders in my FactoryMS ACCESS VBA ORDER BY CASE當

我們定期完成工作的時間爲10天,但有時我們向客戶承諾它會更短(讓我們假設5天)。

我試圖建立一個SQL的順序由minimum Date of the two columns

SELECT id, Status, DeliveryDate, PromiseDate 
FROM CustomerOrderT 
WHERE Status > 2 and Status <7 
ORDER BY CASE WHEN DeliveryDate > PromiseDate then PomiseDate ELSE DeliveryDate END; 

,但我得到從MS Access問題消息。也許把它寫正確 問題按摩附

enter image description here

謝謝

回答

1

在MS Access,你必須這樣使用的,而不是個案IIF:

SELECT id, Status, DeliveryDate, PromiseDate 
FROM CustomerOrderT 
WHERE Status > 2 and Status <7 
ORDER BY IIF(DeliveryDate > PromiseDate, PromiseDate, DeliveryDate); 
+0

謝謝你的幫助 這是關閉,但如果我需要按兩列排序,我應該如何寫? 例如: ORDER BY IIF(DeliveryDate> PromiseDate,(PromiseDate DeliveryDate),(DeliveryDate PromiseDate)); 這不起作用 – idanVaza

+0

這沒有任何意義。只有一列。請重新說明。 – Gustav

+0

第二個順序對結果沒有影響。只有當您想在PromiseDate和DeliveryDate相等時按第三列排序。然後你會在整個IIF後面添加第三列, – Mono