MS-Access 2003基于表达式限制查询结果

时间:2012-12-20 15:20:07

标签: sql ms-access-2003

我有一个提取假期摘要信息的查询。我想将结果限制在大于当前的周年日期。当我只使用周年纪念表达式查询时,周年表达式工作正常。当我输入Where子句时,它会提示周年纪念日。在没有Where子句的情况下执行exp [ression并呈现周年日期。

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], Month([WM DOH]) & "/" & Day([WM DOH]) & "/" & Year(Date()) AS Anniversary
FROM SchedulingLog INNER JOIN Roster ON SchedulingLog.UserID = Roster.UserID
WHERE (((SchedulingLog.EventDate)>=[Anniversary]))
GROUP BY SchedulingLog.UserID, SchedulingLog.Category, Month([WM DOH]) & "/" & Day([WM DOH]) & "/" & Year(Date())
HAVING (((SchedulingLog.Category) Like "Vac*"));

我正在寻找的方法是在活动日期之后将总和值限制在表达式周年纪念之后。

基于我对SQL缺乏经验和指导的无助耐心。我开始看到光明了。所以当我拿

DateAdd("yyyy",1,[WM DOH])
it returns the individuals date of Hire and the year advances by 1.
ex. employee DOH 12-25-2003
The expression returns 12-25-2004

我正在将dateAdd调整为类似的东西

DateAdd("yyyy",Year(Date())-1,[WM DOH])
This returns something completely wrong. but illustrates what I am trying to accomplish
desired result ex. 12-25-2011

思想?

1 个答案:

答案 0 :(得分:2)

同样的故事。 Anniversary不是您可以在where子句中引用的字段,它是别名。

WHERE SchedulingLog.EventDate>= 
    DateSerial(Year(Date())-1,Month([WM DOH]) ,Day([WM DOH]))