MS Access - 时间戳日期范围内的多个查询共享条件
MS Access - Multiple Queries shared Criteria in time stamp date range
微软访问 2016,
我有多个查询 - 大约 120 个 - 根据我目前为每个查询手动更新的日期标准收集临时历史记录 - >=#8/1/2021#
和 <#9/1/2021#
- 2021 年 8 月。
What would be the best solution to update this in one place so all queries could refer to that one date range?
示例查询:(通常为 43 个参数点)
SELECT
History1HourAverage.TimeStamp,
History1HourAverage.Parameter001,
History1HourAverage.Value001,
History1HourAverage.Parameter002,
History1HourAverage.Value002,
History1HourAverage.Parameter003,
History1HourAverage.Value003,
History1HourAverage.Parameter004,
History1HourAverage.Value004
FROM History1HourAverage
WHERE
(
(
***(History1HourAverage.TimeStamp)>=#8/1/2021#
AND (History1HourAverage.TimeStamp)<#9/1/2021#
)***
AND ((History1HourAverage.Parameter001)="10S8MApp.nvoSpaceTemp")
AND ((History1HourAverage.Parameter002)="10S9MApp.nvoSpaceTemp")
AND ((History1HourAverage.Parameter003)="10S10MApp.nvoSpaceTemp")
AND ((History1HourAverage.Parameter004)="10S11MApp.nvoSpaceTemp")
);
谢谢
几个选项:
两者都
添加一个名为 DateRange 的 table,它包含两个字段 StartDate 和 EndDate。在 table 中输入一条记录,其中包含您要用于查询的日期范围。编辑您的每个查询并包括 DateRange table。将查询条件设置为 WHERE History1HourAverage.TimeStamp >= DateRange.StartDate And History1HourAverage.TimeStamp < DateRange.EndDate
或者
创建一个具有两个函数的VBA模块
Public Function StartDate() As Date
StartDate = #8/1/2021#
End Function
Public Function EndDate() As Date
EndDate = #9/1/2021#
End Function
将查询的查询条件设置为WHERE History1HourAverage.TimeStamp >= StartDate() And History1HourAverage.TimeStamp < EndDate()
如果您想使用不同的日期范围,您可以 (1) 编辑 DateRange table 中的数据,或 (2) 编辑您的函数以 return 新日期。
微软访问 2016,
我有多个查询 - 大约 120 个 - 根据我目前为每个查询手动更新的日期标准收集临时历史记录 - >=#8/1/2021#
和 <#9/1/2021#
- 2021 年 8 月。
What would be the best solution to update this in one place so all queries could refer to that one date range?
示例查询:(通常为 43 个参数点)
SELECT
History1HourAverage.TimeStamp,
History1HourAverage.Parameter001,
History1HourAverage.Value001,
History1HourAverage.Parameter002,
History1HourAverage.Value002,
History1HourAverage.Parameter003,
History1HourAverage.Value003,
History1HourAverage.Parameter004,
History1HourAverage.Value004
FROM History1HourAverage
WHERE
(
(
***(History1HourAverage.TimeStamp)>=#8/1/2021#
AND (History1HourAverage.TimeStamp)<#9/1/2021#
)***
AND ((History1HourAverage.Parameter001)="10S8MApp.nvoSpaceTemp")
AND ((History1HourAverage.Parameter002)="10S9MApp.nvoSpaceTemp")
AND ((History1HourAverage.Parameter003)="10S10MApp.nvoSpaceTemp")
AND ((History1HourAverage.Parameter004)="10S11MApp.nvoSpaceTemp")
);
谢谢
几个选项:
两者都
添加一个名为 DateRange 的 table,它包含两个字段 StartDate 和 EndDate。在 table 中输入一条记录,其中包含您要用于查询的日期范围。编辑您的每个查询并包括 DateRange table。将查询条件设置为 WHERE History1HourAverage.TimeStamp >= DateRange.StartDate And History1HourAverage.TimeStamp < DateRange.EndDate
或者
创建一个具有两个函数的VBA模块
Public Function StartDate() As Date
StartDate = #8/1/2021#
End Function
Public Function EndDate() As Date
EndDate = #9/1/2021#
End Function
将查询的查询条件设置为WHERE History1HourAverage.TimeStamp >= StartDate() And History1HourAverage.TimeStamp < EndDate()
如果您想使用不同的日期范围,您可以 (1) 编辑 DateRange table 中的数据,或 (2) 编辑您的函数以 return 新日期。