froggiebeckie
Registered User.
- Local time
- Today, 05:15
- Joined
- Oct 11, 2002
- Messages
- 104
I've seen some threads on this, but I can't make the answers work for me.
I have a db where I track PMs; completion date per equipment, with calculated due dates based on established frequency compared to last completed date.
No problem.
Now, my overlords have decided that we need to keep track of whether or not the PMs were completed on time. So I need to return the most recent 2 completion dates for each piece of equipment.
I can then do the calculations to determine if the latest PM was completed on time or not.
Here's the SQL of my last attempt at a query for this, but it returns all the records, not just the last 2 for each piece of equipment. When I try to add a sub query to the Criteria line, I get syntax error messages.
SELECT [REQUIRED PM TBL].EQUIPMENT, [COMPLETED PMS TBL].[DATE COMPLETED], [REQUIRED PM TBL].FREQ, [COMPLETED PMS TBL].[REQUIRED PM ID]
FROM [COMPLETED PMS TBL] RIGHT JOIN [REQUIRED PM TBL] ON [COMPLETED PMS TBL].[REQUIRED PM ID] = [REQUIRED PM TBL].[REQUIRED PM ID]
WHERE ((([REQUIRED PM TBL].[OUT OF SERVICE])=False))
GROUP BY [REQUIRED PM TBL].EQUIPMENT, [COMPLETED PMS TBL].[DATE COMPLETED], [REQUIRED PM TBL].FREQ, [COMPLETED PMS TBL].[REQUIRED PM ID]
ORDER BY [REQUIRED PM TBL].EQUIPMENT, [COMPLETED PMS TBL].[REQUIRED PM ID] DESC , [COMPLETED PMS TBL].[DATE COMPLETED] DESC;
Can you aim me in the right direction, please.
BeckieO:banghead:
I have a db where I track PMs; completion date per equipment, with calculated due dates based on established frequency compared to last completed date.
No problem.
Now, my overlords have decided that we need to keep track of whether or not the PMs were completed on time. So I need to return the most recent 2 completion dates for each piece of equipment.
I can then do the calculations to determine if the latest PM was completed on time or not.
Here's the SQL of my last attempt at a query for this, but it returns all the records, not just the last 2 for each piece of equipment. When I try to add a sub query to the Criteria line, I get syntax error messages.
SELECT [REQUIRED PM TBL].EQUIPMENT, [COMPLETED PMS TBL].[DATE COMPLETED], [REQUIRED PM TBL].FREQ, [COMPLETED PMS TBL].[REQUIRED PM ID]
FROM [COMPLETED PMS TBL] RIGHT JOIN [REQUIRED PM TBL] ON [COMPLETED PMS TBL].[REQUIRED PM ID] = [REQUIRED PM TBL].[REQUIRED PM ID]
WHERE ((([REQUIRED PM TBL].[OUT OF SERVICE])=False))
GROUP BY [REQUIRED PM TBL].EQUIPMENT, [COMPLETED PMS TBL].[DATE COMPLETED], [REQUIRED PM TBL].FREQ, [COMPLETED PMS TBL].[REQUIRED PM ID]
ORDER BY [REQUIRED PM TBL].EQUIPMENT, [COMPLETED PMS TBL].[REQUIRED PM ID] DESC , [COMPLETED PMS TBL].[DATE COMPLETED] DESC;
Can you aim me in the right direction, please.
BeckieO:banghead: