我有一个工作正常的查询,除了在某些日期之间不计算。我最初的查询 SQL 是
SELECT
Roster.UserID,
SchedulingLog.Category,
Sum(IIf([CatDetail] Like '*Gain*',[Value],0)) AS Gain,
Sum(IIf([CatDetail] Like '*Used*',[Value],0))+Sum(IIf([CatDetail] Like 'Adj*',[Value],0)) AS Used,
[Gain]+[Used] AS [Left]
FROM SchedulingLog INNER JOIN Roster ON SchedulingLog.UserID = Roster.UserID
WHERE (((SchedulingLog.EventDate)>DateSerial(Year(Date()),5,20)))
GROUP BY Roster.UserID, SchedulingLog.Category
HAVING (((SchedulingLog.Category) Like "DH*" Or (SchedulingLog.Category) Like "Comp*"));
此 SQL 工作正常,直到新的一年。我在WHERE
语句中修改了我的代码以使用BETWEEN
限定符,但我无法让它工作。这是新的 SQL...
SELECT
Roster.UserID,
SchedulingLog.Category,
Sum(IIf([CatDetail] Like '*Gain*',[Value],0)) AS Gain,
Sum(IIf([CatDetail] Like '*Used*',[Value],0))+Sum(IIf([CatDetail] Like 'Adj*',[Value],0)) AS Used,
[Gain]+[Used] AS [Left]
FROM SchedulingLog INNER JOIN Roster ON SchedulingLog.UserID = Roster.UserID
WHERE (((SchedulingLog.EventDate) Between DateSerial(Year(Date()-1),5,20) And DateSerial(Year(Date()),5,20)))
GROUP BY Roster.UserID, SchedulingLog.Category
HAVING (((SchedulingLog.Category) Like "DH*" Or (SchedulingLog.Category) Like "Comp*"));
新 SQL 的目的是收集去年 5-20-2012 和今年 5-20-2013 之间的信息。我在哪里错过了船?