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

Determine Max Age of Unresolved Items For Last 30 Dys 1

Status
Not open for further replies.

Du2good

Technical User
May 9, 2005
41
US
Can I get this?
MyTable has items [ItemID] added to it daily [ReceivedDt].
ItemID's may be resolved [ResolvedDt], on or after the [ReceivedDT].
Looking at the unresolved items, can I find out what the oldest item was, that was not yet been resolved, for each day there was an item that was resolved?
I believe a sub query is in order here but havn't had any success.
 
but havn't had any success
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
trying to use this subquery:
SELECT Max([ResolveDt]-[ReceiptDt]) AS Age, Max(MyTable.ReceiptDt) AS MaxOfReceiptDt, MyTable.ResolveDt, Count(MyTable.ItemID) AS CountOfItemID
FROM MyTable
GROUP BY MyTable.ResolveDt
HAVING (((MyTable.ResolveDt) Is Not Null));

With this outer query:
SELECT Max([ResolveDt]-[ReceiptDt]) AS Age, [resolveDt]-[receiptDt] AS MyRcptDt, Max(MyTable.ReceiptDt) AS MaxOfReceiptDt, MyTable.ResolveDt, Count(MyTable.ItemID) AS CountOfItemID
FROM MyTable
GROUP BY [resolveDt]-[receiptDt], MyTable.ResolveDt;


but I'm in over my head. At this point I'm not even sure which field should have the Where clause. It's a mess in process.

Thank you
 
A starting point:
SQL:
SELECT E.ResolveDt,MIN(O.ReceiptDt) AS OldestNotYetResolved,E.ResolveDt-MIN(O.ReceiptDt) AS Age
FROM MyTable O
,(SELECT DISTINCT ResolveDt FROM MyTable WHERE ResolveDt IS NOT NULL) E
WHERE O.ReceiptDt<=E.ResolveDt AND (O.ResolveDt IS NULL OR O.ResolveDt>E.ResolveDt)
GROUP BY E.ResolveDt

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you again PHV.

I'm surprised how bracketing affects the subquery, my actual table had poor design with spaces in the field names.
When I tried your solution, and added brackets to the field [Resolved Dt], Access gave me an error.
With a temp table, and field name as [ResolvedDt], your solution worked great.
Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top