【问题标题】:Pulling records from Access table based off of date根据关闭日期从 Access 表中提取记录
【发布时间】:2018-12-28 15:25:45
【问题描述】:

我目前正在尝试根据前一天提取特定记录。我主要在设置查询时使用 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;

【问题讨论】:

  • 您的关闭日期只是一个日期吗?那么该日期与 Date() 的格式相同吗?如果格式不同(意味着一个人有时间或其他东西),他们将不匹配)
  • Where 子句不会导致弹出窗口,因此[Closed Date] 是代码拼写错误或缺失。
  • @Brad 结束日期只是一个日期,数据类型是日期/时间,但在设计视图中没有格式。这可能是问题吗?
  • @Gustav 那会导致弹出什么?
  • 如果您能发布完整的查询和一些示例数据,将会很有帮助。

标签: sql database ms-access


【解决方案1】:

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

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

然而,当您在 cmets 中发布完整的查询时,您的数据源实际上称为 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;

这将表明弹出的原因以及为什么不会获得任何结果。

【讨论】:

  • 抱歉,CurrentData 应该是 CurrentTable
猜你喜欢
  • 2018-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-19
  • 2019-06-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多