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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help "Newest date Query with a twist"

Status
Not open for further replies.

oldgoldone

Technical User
Apr 24, 2004
13
US
I have a querry named "reminder labels" that get data from
"Service tabel" & "Customer Tabel'
what i need to do is have the query ask the user what "next due dates" they whant to search for then get the "newest service dates" fore each customer I have got the part were the query get the newest service dates but cant get next due date range part

"SQL so far"
SELECT Customers.TankID, Customers.[First Name], Customers.[Last Name], Customers.Address, Customers.City, Customers.State, Customers.[Zip Code], Customers.[Filter?], S1.[Date of Service]
FROM Customers INNER JOIN Service AS S1 ON Customers.TankID = S1.TankID
WHERE (((S1.[Date of Service]) In (SELECT Max([Date of Service]) FROM Service WHERE Service.TankId = S1.TankId)));
 
What is the "next due date range"?

Could you clarify what the Date of Service means? Is that the date that the tank was serviced? Does "newest service date" mean the date of last service?

When is the next service due? In 30 days? In six months?

When the computer prompts me to enter the "next due date", and I enter a date what do I get? A list of my tanks that are due to be serviced on that date? Or after that date? Or before that date?

I will assume the "next due date" means list the tanks that need service before that date and that the due date is 30 days after the last service.

Code:
SELECT Customers.TankID,
       DATEADD( "d", 30, S1.[Date of Service] ) AS DateServiceDue
FROM Customers
JOIN Service S1 ON
       S1.TankID = Customers.TankID
WHERE Customers.customer_id = [me]
  AND S1.[Date of Service] = ( SELECT Max([Date of Service])
                         FROM Service
                         WHERE Service.TankId = S1.TankId
                       )
  AND DATEADD( "d", 30, S1.[Date of Service] ) < [Next Due Date]

This should give a list of my tanks which are due for service before the date I entered for [Next Due Date].

So maybe the piece you needed was the DateAdd function?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top