2015-04-14 104 views
0

我有一個MS Access數據庫與40個類似的表。爲簡單起見,下面僅列出一對夫婦。如果該行的日期是昨天,我想從行中獲取3個數據單元格。數據來自他們拒絕放棄的其他員工的自制電子表格。所以我不能更改列名或在同一個工作簿模板中全部獲取它們。我已經嘗試了下面的代碼的一些變化,但我不能讓日期工作正確。如果我放棄WHERE語句,它將返回所有內容。但我真的需要它削減。提前致謝!爲什麼我的「WHERE」語句不能在sql中工作?

SELECT [Customer name],[$ Amount], [Quote Completed] 
FROM 1081 
WHERE [Quote Completed] = date()-1 
UNION 

SELECT [Customer name],[$ Amount], [Quote Completed] 
FROM 1145 
WHERE [Quote Completed] = date()-1 
UNION 

SELECT [Customer name],[$ Amount], [Quote Completed] 
FROM 1149 
WHERE [Quote Completed] = date()-1 
UNION 

SELECT [Customer name],[$ Amount], [Quote Completed] 
FROM 1228 
WHERE [Quote Completed] = date()-1 
UNION 

SELECT [Customer name],[$ Amount], [Quote Completed] 
FROM 1353 
WHERE [Quote Completed] = date()-1 
; 
+0

嘗試使用隱去(日期() - 1) – DesirePRG

+0

如果您硬編碼日期值會發生什麼?它會返回數據嗎?認爲它可能是日期函數的語法問題 – Jared

+0

'[Customer name]'是什麼語法? –

回答

1

你真的需要在你的工會的每個部分,其中的條件?或者你只是想過濾整個結果?

SELECT * FROM (
    SELECT [Customer name],[$ Amount], [Quote Completed] 
    FROM 1081 
    UNION 
    SELECT [Customer name],[$ Amount], [Quote Completed] 
    FROM 1145 
    UNION 
    SELECT [Customer name],[$ Amount], [Quote Completed] 
    FROM 1149 
    UNION 
    SELECT [Customer name],[$ Amount], [Quote Completed] 
    FROM 1228 
    UNION 
    SELECT [Customer name],[$ Amount], [Quote Completed] 
    FROM 1353) U 
WHERE [Quote Completed] = date()-1 
-1

您可能需要使用DATEADD:

SELECT [Customer name],[$ Amount], [Quote Completed] 
FROM 1081 
WHERE [Quote Completed] = DateAdd('d',-1, date()) 

添加鏈接:http://www.techonthenet.com/access/functions/date/dateadd.php

+0

當我點擊Run時,它仍然沒有顯示任何結果。這只是我的第四個數據庫,所以我可能會錯過一些簡單的愚蠢。 – msiudut

+0

訪問允許使用普通的加法和減法操作符來添加或減去日期/天數值。 –

+0

分享它的作品!多謝你們! – msiudut

-2
SELECT [Customer name],[$ Amount], [Quote Completed] 
FROM 1081 
WHERE ([Quote Completed] = date()-1) 
UNION 

SELECT [Customer name],[$ Amount], [Quote Completed] 
FROM 1145 
WHERE ([Quote Completed] = date()-1) 
UNION 

SELECT [Customer name],[$ Amount], [Quote Completed] 
FROM 1149 
WHERE ([Quote Completed] = date()-1) 
UNION 

SELECT [Customer name],[$ Amount], [Quote Completed] 
FROM 1228 
WHERE ([Quote Completed] = date()-1) 
UNION 

SELECT [Customer name],[$ Amount], [Quote Completed] 
FROM 1353 
WHERE ([Quote Completed] = date()-1) 
; 
相關問題