Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Based Query off the Max of the Date

Status
Not open for further replies.

F15

Programmer
Nov 21, 2002
7
US
I need to write a query which identifies the latest date in the database and then goes back 3 months. In other words, if the latest data is for October 2002, then I need the data for August, September and October. When the data is updated with November data, then the query should pick up September, October, and November data.

I have tried the following SQL:
Code:
SELECT Sum(Daily.Amount) AS SumOfAmount
FROM Daily
WHERE (((Monthly.Date) Between DateAdd("m",-3,Date()) And Date()));
[code]
but before the November data is loaded, this will only pick up Sept and Oct data if it is currently November.

Can I include the Max function within the DateAdd function?
Thanks!
 
This looks like a SQL Server question rather than a BRIO question. You can include the max date in a sub-query.

You would write:

select Sum(Daily.Amount) AS SumOfAmount
from Daily
where
Daily.Date >= (select DateAdd("m",-3, max(Daily.Date))
from Daily)
 
Thanks for your suggestion. This has worked very well. I appreciate the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top