为什么赢得了我的" WHERE"语句在sql中工作?

时间:2015-04-14 19:03:56

标签: sql ms-access

我有一个包含40个类似表的MS Access数据库。为简单起见,下面仅列出了几个。如果该行中的日期是昨天,我想从一行中获取3个数据单元格。这些数据来自其他员工的自制电子表格,他们拒绝放弃。因此,我无法更改列名或将它们全部放在同一工作簿模板上。我在下面的代码中尝试了一些变体,但我无法让日期正常工作。如果我删除WHERE语句,它将返回所有内容。但我真的需要它削减。提前谢谢!

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
;

3 个答案:

答案 0 :(得分: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 :(得分:-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

答案 2 :(得分:-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)
;