3

我有一个查询可以完美地提取数据,但有一个例外,我希望数据总和在周年纪念日重新开始。我目前的查询是;

"qry_Vac2"
UserID    Category    Gain    Used    Left

查询 SQL;

SELECT 
    SchedulingLog.UserID,
    SchedulingLog.Category,
    Sum(IIf([CatDetail] Like 'Ann*',[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
GROUP BY SchedulingLog.UserID, SchedulingLog.Category
HAVING (((SchedulingLog.Category) Like "Vac*"));

我对修改周年纪念活动后重置总和的想法;

   SELECT Roster.UserID, Roster.[WM DOH], Roster.Schedule, Month([WM DOH]) & "/" & Day([WM DOH]) & "/" & Year(Date()) AS [Anniversary Date], SchedulingLog.Category, Sum(IIf([CatDetail] Like 'Ann*',[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)>[Anniversary Date]))
   GROUP BY Roster.UserID, Roster.[WM DOH], Roster.Schedule, Month([WM DOH]) & "/" & Day([WM DOH]) & "/" & Year(Date()), SchedulingLog.Category;

修改后的查询不返回任何数据。想法?

4

1 回答 1

2

周年日期不作为可以在 where 语句中引用的字段存在。要决定做什么,您需要发布 SchedulingLog 日期的格式。

schedulinglog.eventdate  > Month([WM DOH]) & "/" & Day([WM DOH]) & "/" & Year(Date())

可能会奏效。

或者

schedulinglog.eventdate  > DateSerial(Year(Date(),Month([WM DOH]),Day([WM DOH]))

或者

schedulinglog.eventdate  > DateAdd("yyyy",1,[WM DOH])
于 2012-12-19T12:25:22.737 回答