根据日期从Access表中提取记录

时间:2018-12-28 15:25:45

标签: sql database ms-access

我目前正在尝试根据前一天的情况提取特定记录。我主要在设置查询时使用SQL。我选择了所需的特定字段,但在末尾设置了where语句,如下所示:

WHERE ((([CurrentData].[Closed Date])=Date()-1));

我收到一个弹出框,以MM / DD / YYYY格式输入的任何日期都没有结果。任何帮助将不胜感激,因为我觉得我在某处只想念一件事。


编辑:

样本数据:

| ID | Status     | ProductID | Request Date | ReqReviewed | Closed Date | 
|----+------------+-----------+--------------+-------------+-------------| 
| 1A | Successful | 0001      | 09/10/2000   | Yes         | 09/20/2000  | 
| 2C | Successful | 0001      | 07/20/2001   | Yes         | 07/29/2001  | 
| 5B | Successful | 0005      | 04/08/2001   | Yes         | 05/20/2001  |

查询:

INSERT INTO ReconReport ( [ID], [Status], [ProductID], [Closed Date]) 
SELECT 
    CurrentTable.[ID], 
    CurrentTable.[Status], 
    CurrentTable.[ProductID], 
    CurrentTable.[Closed Date] 
FROM 
    CurrentTable 
WHERE
    [CurrentTable].[Closed Date] = Date()-1;

1 个答案:

答案 0 :(得分:0)

问题中的第一个WHERE子句引用了一个名为CurrentData的数据源:

WHERE ((([CurrentData].[Closed Date])=Date()-1));

因此,当您在评论中发布完整查询时,您的数据源实际上称为CurrentTable

INSERT INTO ReconReport ( [ID], [Status], [ProductID], [Closed Date]) 
SELECT 
    CurrentTable.[ID], 
    CurrentTable.[Status], 
    CurrentTable.[ProductID], 
    CurrentTable.[Closed Date] 
FROM 
    CurrentTable 
WHERE
    [CurrentTable].[Closed Date] = Date()-1;

这将指示弹出窗口的原因,以及为何无法获得结果。