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!

Previous time peroid query

Status
Not open for further replies.

bfamo

Technical User
Feb 16, 2006
132
NO
Hi,

I'm using this "current week to date"-query:


Code:
SELECT Table.DateField
FROM Table
WHERE [Table.DateField] BETWEEN 
 
DateAdd("d", -((Weekday(Date()) - 1)), Date()) AND 
 
Date();

How can I get this SQL statement to go one week back starting with [LastOfDateField]?

Thanks!
 
How about:
Code:
BETWEEN [LastOfDateField] AND [LastOfDateField]-7
Hope this helps

HarleyQuinn
---------------------------------
You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Hmmm... that didnt seem to do the trick. I might have to give a better explanation of what I want to achieve.

I'm working on a report that's going to gather data from inspections done at our clients sites. We do these inspections at multiple sites within one week for each customer. Each site is inspected separately, and therefore get its own recordset in the database.

The query behind the report should do the following:
1) Ask for customer ID (Forms!FrmInspection!CustomerID)
2) Check when the last inspection was performed (ex. Last(TblInspection.Date))
3) Gather all recordsets from LastOfDate and 7 days back.

Now, is this possible to do in a simple query? LastOfDate require Totals to be enabled, and that sets all other fields to "Group by", which kind of messes it all up.

Any suggestions on how to solve this is greatly appreciated!!! thanks ;)
 
A starting point:
Code:
SELECT A.*
FROM TblInspection A INNER JOIN (
SELECT CustomerID, Max([Date]) AS LastOfDateField FROM TblInspection GROUP BY CustomerID
) B ON A.CustomerID = B.CustomerID
WHERE A.Date Between B.LastOfDateField-7 AND B.LastOfDateField

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top