当我尝试 IIF 语句时,我无法让 Where 语句正常工作。我尝试了一些 sql 变体,但无济于事。我想做的是计算假期增益到某个日期。当我单独使用我的 Between 语句时,它可以正常工作。当我在系统时钟超过 13 年 5 月 20 日之后尝试重置计数器时,当它应该为刚刚过去的阵亡将士纪念日假期显示 1 时,我没有返回任何结果。我无法弄清楚正确语法的代码段开是
WHERE (((SchedulingLog.EventDate)=IIf(Date()>DateSerial(Year(Date()),5,20),((SchedulingLog.EventDate) Between DateSerial(Year(Date()),5,20) And DateSerial(Year(Date())+1,5,20)),((SchedulingLog.EventDate) Between DateSerial(Year(Date())-1,5,20) And DateSerial(Year(Date()),5,20)))))
下面是我的整个sql。
SELECT Roster.UserID, SchedulingLog.Category,
Sum(IIf([CatDetail] Like '*Gain*',[Value],0)) AS Gain, DateSerial(Year(Date()),5,20) AS ResetDate, Date() AS [Date]
FROM SchedulingLog INNER JOIN Roster ON SchedulingLog.UserID = Roster.UserID
WHERE (((SchedulingLog.EventDate)=IIf(Date()>DateSerial(Year(Date()),5,20),((SchedulingLog.EventDate) Between DateSerial(Year(Date()),5,20) And DateSerial(Year(Date())+1,5,20)),((SchedulingLog.EventDate) Between DateSerial(Year(Date())-1,5,20) And DateSerial(Year(Date()),5,20)))))
GROUP BY Roster.UserID, SchedulingLog.Category, DateSerial(Year(Date()),5,20), Date()
HAVING (((SchedulingLog.Category) Like "DH*" Or (SchedulingLog.Category) Like "Comp*"));
任何帮助将不胜感激。