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

Pass query result DateMax to variable 1

Status
Not open for further replies.

Du2good

Technical User
May 9, 2005
41
US
I have the SQL below that will provide the MaxOfRptDt for a Report.
Code:
SELECT tblReportDates.Report, tblReportDates.Action, Max(tblReportDates.RptDt) AS MaxOfRptDt
FROM tblReportDates
GROUP BY tblReportDates.Report, tblReportDates.Action
HAVING (((tblReportDates.Report) Like "*CSH06") AND ((tblReportDates.Action)="Finish"));
I want to take the MaxOfRptDt value from the above strSQL and pass it to another strSQL, replacing Date()-3 with MaxOfRptDt.
Code:
"SELECT tblAccount.PI_id, tblAccount.External_Status_cd, tblAccount.Fraud_dt " & _
"INTO  Strqry &  " & _
"FROM tblAccount " & _
"WHERE (((tblAccount.Fraud_dt)>=Date()-3));"

A function that would return the MaxOfRptDt value from the first strSQL is my first guess. And then pass that to the 2nd strsql.... but I need help.
Thank you

Du2good
 
You could do this with a sub query, for example:
[tt]SELECT tblAccount.PI_id, tblAccount.External_Status_cd, tblAccount.Fraud_dt INTO Strqry
FROM tblAccount
WHERE (((tblAccount.Fraud_dt) In (SELECT Max(tblReportDates.RptDt) AS MaxOfRptDt
FROM tblReportDates
GROUP BY tblReportDates.Report, tblReportDates.Action
HAVING (((tblReportDates.Report) Like "*CSH06") AND ((tblReportDates.Action)="Finish"));
)));[/tt]

You will undoubtably get a better version if you post in the Microsoft: Access Queries and JET SQL forum701. Alternatively, you could use a recordset.

I am a little confused by your first query, is it possible for you to simply look up the max date? For example:
[tt]dteDate = DMax("RptDt", "tblReportDates", "Report Like '*CSH06' AND Action='Finish'")[/tt]

 
Thank you very much Remou [thumbsup2]!!

The Dmax function is exactly what I needed. I should have been able to find a function that does the same as MAX in a query...I want to say Duh [thumbsdown]to myself.

Thank you for seeing through my confusion.

Plus I now have an understanding of subqueries!!

Thank you again, and have star for seeing through my haze!!
Du2Good

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top