I want to compare flight data to fuel purchase data and make sure our planes were at the place the fuel vendor says they were.
I have one table of flight data (flight), one table of Vendor info (Vendors) and one union query of fuel invoices (Union Master Invoices). flight has columns nNumber, arrDate, and arrLocation. Vendors has columns VendorID and AirportID. UMI has columns TransDate, VendorID, and TailNumber. UMI gets it's location (AirportID) from a join on VendorID.
The following code is a start towards what I need:
[CODE=SQL]SELECT [Union Master Invoices].TransDate, [Union Master Invoices].TailNumber, flight.arrLocat ion, Vendors.Airport ID, [Union Master Invoices].VendorID
FROM ([Union Master Invoices] INNER JOIN flight ON ([Union Master Invoices].TransDate = flight.arrDate) AND ([Union Master Invoices].TailNumber = flight.nNumber) ) INNER JOIN Vendors ON (Vendors.Airpor tID = flight.arrLocat ion) AND ([Union Master Invoices].VendorID = Vendors.VendorI D);[/CODE]
Now this only checks to see if the airplane was at the same airport given from the fuel data and flight data on the same date (theoretically a perfect match!). But alas, our data isn't perfect, and we need some leeway. What I need is to know if there is a match of the locations (fuel data (AirportID) and the flight data (arrLocation)) within a day of the flight date (arrDate); that is, arrDate =, +1, or -1 TransDate (3 criteria). I don't know how to get this to work correctly, as a simple criteria selection doesn't work because it will pull multiple rows. I just need to know if the airplane was there any of those 3 days.
What I'm thinking is some sort of temporary list (or complex iif statement), where for each TailNumber for each TransDate, get list of [arrLocation]'s where arrDate is =,+1, or -1 TransDate, and check if AirportID is in list. It's kinda there in my head conceptually but I don't know how to write that out, or if that's event he best route. Thanks for the help. And please let me know if I need to add more detail!
I have one table of flight data (flight), one table of Vendor info (Vendors) and one union query of fuel invoices (Union Master Invoices). flight has columns nNumber, arrDate, and arrLocation. Vendors has columns VendorID and AirportID. UMI has columns TransDate, VendorID, and TailNumber. UMI gets it's location (AirportID) from a join on VendorID.
The following code is a start towards what I need:
[CODE=SQL]SELECT [Union Master Invoices].TransDate, [Union Master Invoices].TailNumber, flight.arrLocat ion, Vendors.Airport ID, [Union Master Invoices].VendorID
FROM ([Union Master Invoices] INNER JOIN flight ON ([Union Master Invoices].TransDate = flight.arrDate) AND ([Union Master Invoices].TailNumber = flight.nNumber) ) INNER JOIN Vendors ON (Vendors.Airpor tID = flight.arrLocat ion) AND ([Union Master Invoices].VendorID = Vendors.VendorI D);[/CODE]
Now this only checks to see if the airplane was at the same airport given from the fuel data and flight data on the same date (theoretically a perfect match!). But alas, our data isn't perfect, and we need some leeway. What I need is to know if there is a match of the locations (fuel data (AirportID) and the flight data (arrLocation)) within a day of the flight date (arrDate); that is, arrDate =, +1, or -1 TransDate (3 criteria). I don't know how to get this to work correctly, as a simple criteria selection doesn't work because it will pull multiple rows. I just need to know if the airplane was there any of those 3 days.
What I'm thinking is some sort of temporary list (or complex iif statement), where for each TailNumber for each TransDate, get list of [arrLocation]'s where arrDate is =,+1, or -1 TransDate, and check if AirportID is in list. It's kinda there in my head conceptually but I don't know how to write that out, or if that's event he best route. Thanks for the help. And please let me know if I need to add more detail!
Comment