If you don't know SQL at all, it's best to break the problem into pieces.
1) display an asset with the current mileage (G)
Create a new query, select tables tblAssets and tblAssets_Hrs_Miles. Select the field AssetID and just those fields needed to recognise the asset (as few as possible). From the second table, take only End_Of_Day_M???. Display the total row, leave "Group By" for all but the last, where you select Max.
This should provide (G). Save it, for example as qtotAssets_Current.
2) get last services
Create a new query on tblService_Record. Choose only three fields: Asset_ID, Service_Type_ID, and HrsMiles. Again, group on the first two, and use Max on the last one.
This provides (E) and (F). You can call it qtotService_Last
3) get the maintenance schedule
If the combination Asset_ID & Service_Type_ID is unique, you can skip this part. If not, proceed exactly like in 2), but for that table.
4) bring it together
In a new query, display qtotAssets_Current, qtotService_Last (linked on Asset_ID), and tblMaintenance (or the query you built for it -- linked on both Asset_ID and Service_Type_ID).
You should now have one row for each asset and each service type, with the values (G)(E)(A) in one row and (G)(F)(B) in the next. All that's left is then to compare them in an expression or in a criteria.
It's not as complicated as it seems. The SQL performing that in one query would be and then some.
Good luck!
(°v°)
Main Topics
Browse All Topics





by: JMTinCLTPosted on 2009-11-02 at 17:30:04ID: 25725456
Well you could just do a query on tblAssets_Hrs_Miles and join it to tblAssets on Asset_ID where PM_at_Hrs_Mi => X
However, this is a pretty complicated question and not one that I can easily answer as it has many variables. I can say that your database layout seems acceptable.