Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS-Access 2003 SQL modification for resetting sum values based on a date

Tags:

sql

ms-access

I have a query that is pulling data perfectly with one exception, I want the data sums to start over at an anniversary date. My current query is;

"qry_Vac2"
UserID    Category    Gain    Used    Left

the querys 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*"));

My ideas for a modification to reset the sum after anniversary event;

   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;

The modified query returns no data. Thoughts?

like image 294
Desert Spider Avatar asked Mar 10 '26 23:03

Desert Spider


1 Answers

Anniversary date does not exists as a field that you can reference in a where statement. To decide what to do, you need to post the format of the SchedulingLog date.

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

Might work.

Or

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

Or

schedulinglog.eventdate  > DateAdd("yyyy",1,[WM DOH])
like image 61
Fionnuala Avatar answered Mar 13 '26 12:03

Fionnuala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!