T
timbits35 via AccessMonster.com
Hi,
I have a database that tracks yearly plans for a personal trainer. Each
athlete usually renews every year and therefore one athlete can have many
contracts. I have a contract date in the sales table and then I have a query
where I calculate the renew date as 364 days later than the contract date. In
my query I would like to show only the most recent contract for each athlete.
I have tried the totals query and the putting Max in the Renew date
calculated field which didn't work nor did putting Max in the contract date.
I do not get the most recent contract. Here is the SQL which Access generated
: All other fields in the query say Group By.
SELECT tblmembers.Lname, tblmembers.Fname, tblsales.contractyear, tblsales.
contractdate, Max(IIf(tblsalesdetails!ServiceID=8,[contractdate]+182,
[contractdate]+364)) AS renewdate
FROM tblservices INNER JOIN ((tblmembers INNER JOIN tblsales ON tblmembers.
MemberID = tblsales.MemberID) INNER JOIN tblsalesdetails ON tblsales.SalesID
= tblsalesdetails.SalesID) ON tblservices.ServiceID = tblsalesdetails.
ServiceID
GROUP BY tblmembers.Lname, tblmembers.Fname, tblsales.contractyear, tblsales.
contractdate, tblservices.ServiceID
HAVING (((tblservices.ServiceID)<>1))
ORDER BY Max(IIf(tblsalesdetails!ServiceID=8,[contractdate]+182,[contractdate]
+364));
The calculations you see for 182 or 364 depend on whether it may be a 6month
or 1 year contract.
Thank you,
Liane
I have a database that tracks yearly plans for a personal trainer. Each
athlete usually renews every year and therefore one athlete can have many
contracts. I have a contract date in the sales table and then I have a query
where I calculate the renew date as 364 days later than the contract date. In
my query I would like to show only the most recent contract for each athlete.
I have tried the totals query and the putting Max in the Renew date
calculated field which didn't work nor did putting Max in the contract date.
I do not get the most recent contract. Here is the SQL which Access generated
: All other fields in the query say Group By.
SELECT tblmembers.Lname, tblmembers.Fname, tblsales.contractyear, tblsales.
contractdate, Max(IIf(tblsalesdetails!ServiceID=8,[contractdate]+182,
[contractdate]+364)) AS renewdate
FROM tblservices INNER JOIN ((tblmembers INNER JOIN tblsales ON tblmembers.
MemberID = tblsales.MemberID) INNER JOIN tblsalesdetails ON tblsales.SalesID
= tblsalesdetails.SalesID) ON tblservices.ServiceID = tblsalesdetails.
ServiceID
GROUP BY tblmembers.Lname, tblmembers.Fname, tblsales.contractyear, tblsales.
contractdate, tblservices.ServiceID
HAVING (((tblservices.ServiceID)<>1))
ORDER BY Max(IIf(tblsalesdetails!ServiceID=8,[contractdate]+182,[contractdate]
+364));
The calculations you see for 182 or 364 depend on whether it may be a 6month
or 1 year contract.
Thank you,
Liane