您有一个日期/时间参数DATEFIRST,并且您想要选择其 DateCalled值不晚于DATEFIRST之前 3 个工作日的行。我解释这意味着这些是您想要的每个参数值的最新日期......
DATEFIRST 3 workdays previous
--------------- -------------------
Mon, 01/28/2013 Wed, 01/23/2013
Tue, 01/29/2013 Thu, 01/24/2013
Wed, 01/30/2013 Fri, 01/25/2013
Thu, 01/31/2013 Mon, 01/28/2013
Fri, 02/01/2013 Tue, 01/29/2013
Sat, 02/02/2013 Tue, 01/29/2013
Sun, 02/03/2013 Tue, 01/29/2013
我使用 Access 2007 测试了以下查询。它返回与上述 DATEFIRST 模式匹配的结果。
PARAMETERS DATEFIRST DateTime;
SELECT *
FROM your_table AS y
WHERE y.DateCalled < DateAdd(
'd',
Switch(
Weekday([DATEFIRST])=1,-4,
Weekday([DATEFIRST])=2,-4,
Weekday([DATEFIRST])=3,-4,
Weekday([DATEFIRST])=4,-4,
Weekday([DATEFIRST])=5,-2,
Weekday([DATEFIRST])=6,-2,
Weekday([DATEFIRST])=7,-3
),
[DATEFIRST]
);
根据您的评论,我怀疑我误解了您的意图。看来您不想要参数查询。相反,您希望DateCalled
过滤器在查询运行日期前 3 天。如果是这样,则丢弃该PARAMETERS
子句并用 Access'Date()
函数替换[DATEFIRST]
.
SELECT *
FROM your_table AS y
WHERE y.DateCalled < DateAdd(
'd',
Switch(
Weekday(Date())=1,-4,
Weekday(Date())=2,-4,
Weekday(Date())=3,-4,
Weekday(Date())=4,-4,
Weekday(Date())=5,-2,
Weekday(Date())=6,-2,
Weekday(Date())=7,-3
),
Date()
);