Hello all,
I have a small problem I am hoping people can help me out with. Right now, I am converting a spreadheet to Access, and am having trouble mimicing some functionality, and getting similar speed.
Given:
Date Sales
------------------------------
10/30/2002 50
10/31/2002 60
11/1/2002 55
11/4/2002 45
11/5/2002 55
Given an integer variable input on a form (lets say X), for each date, I want the sum Sales for the the next X business days. Sounds easy off the bat, but I need to worry about weekends, so I cannot compare raw dates. I need to determine what the date X days from the start would be (accounting for weekends).
Like i said, I was able to get this to work, but it runs a little too slow for something that may be changed freqently.
Here is the Query that gets the data:
'AddWorkDays' is a function that I wrote. I realize that UDFs are slow, but I was getting the same response time with using IIF's in the Criteria.
If I replace the 'AddWorkDays' function with simple addition (i.e. [tR001A].[dDate] + 1 <= [NextDay].[dDate]), it is much faster, but again, that does not take ignore weekends.
So to bring it all around, is it possible to look at one record, and sum the next X in the table?
Thanks in advance!
Jonathan
I have a small problem I am hoping people can help me out with. Right now, I am converting a spreadheet to Access, and am having trouble mimicing some functionality, and getting similar speed.
Given:
Date Sales
------------------------------
10/30/2002 50
10/31/2002 60
11/1/2002 55
11/4/2002 45
11/5/2002 55
Given an integer variable input on a form (lets say X), for each date, I want the sum Sales for the the next X business days. Sounds easy off the bat, but I need to worry about weekends, so I cannot compare raw dates. I need to determine what the date X days from the start would be (accounting for weekends).
Like i said, I was able to get this to work, but it runs a little too slow for something that may be changed freqently.
Here is the Query that gets the data:
Code:
SELECT tR001A.dDate,
tR001A.Sales,
Sum(NextDay.Sales) AS SumOfSales
FROM tR001A,
tR001A AS NextDay
WHERE AddWorkDays(1,[tR001A].[dDate])<=[NextDay].[dDate]
AND AddWorkDays(X,[tR001A].[dDate])>=[NextDay].[dDate]
GROUP BY tR001A.dDate,
tR001A.Sales
If I replace the 'AddWorkDays' function with simple addition (i.e. [tR001A].[dDate] + 1 <= [NextDay].[dDate]), it is much faster, but again, that does not take ignore weekends.
So to bring it all around, is it possible to look at one record, and sum the next X in the table?
Thanks in advance!
Jonathan