Friends,
I have a problem, which seems straightforward to solve, but I can't get around doing it.
I have a table (tMGT) , which contains the following fields:
AircraftType, AirlineDesignator, Airport, MGT
MGT is minimum ground time. The table actually contains the minimum ground time for given aircraft, airline, airport combinations. However, the whole thing is not "complete"... but some "bulk" entries should be used as fallback, if no specific entry exists...
SCH_MGT
AircraftType AirlineDesignator Airport MGT
319 LH FRA 00:45
319 LH MUC 00:30
320 LH FRA 00:55
319 LH (Null) 01:00
319 (Null) (Null) 01:30
(Null) (Null) (Null) 01:45
I query the table with certain values for Aircraft, Airline and Airport and want to get one MGT back, according to the following rules:
If the table has an entry with all criteria matched then
return the MGT for that specific entry
Else
If the table has an entry with aircraft and airline and isnull(airport) matched then
return that entry for MGT
Else
if the table has an entry with aircraft and isnull(airlinedesignator) and isnull(airport) matched then
return that entry for MGT
Elseif
return the entry where all of aircrafttype, airlinedesignator and Airport are null
I can and am doing this with a hierarchical Dlookup:
Mgtvalue = Nz(dlookup("MGT", "SCH_MGT", "all 3 criteria"), Nz(dlookup("MGT", "SCH_MGT", "2 criteria plus Airport is null"), Nz(dlookup("MGT", SCH_MGT", "1 criterion plus airline is null plus airport is null"),dlookup("MGT", "SCH_MGT", "all are null"))))
this sort of works but is horribly slow if I want to use this in a query itself.
Can somebody helpme, how I can formulate a decent subquery SQL to do the same trick: basically create a query which returns exactly one MGT, depending on the selection of the above 3 criteria, and assuming that the underlying SCH_MGT table has at least an entry will criteria set to Null, which is the ultimate fallback.
Many thanks
Jan
I have a problem, which seems straightforward to solve, but I can't get around doing it.
I have a table (tMGT) , which contains the following fields:
AircraftType, AirlineDesignator, Airport, MGT
MGT is minimum ground time. The table actually contains the minimum ground time for given aircraft, airline, airport combinations. However, the whole thing is not "complete"... but some "bulk" entries should be used as fallback, if no specific entry exists...
SCH_MGT
AircraftType AirlineDesignator Airport MGT
319 LH FRA 00:45
319 LH MUC 00:30
320 LH FRA 00:55
319 LH (Null) 01:00
319 (Null) (Null) 01:30
(Null) (Null) (Null) 01:45
I query the table with certain values for Aircraft, Airline and Airport and want to get one MGT back, according to the following rules:
If the table has an entry with all criteria matched then
return the MGT for that specific entry
Else
If the table has an entry with aircraft and airline and isnull(airport) matched then
return that entry for MGT
Else
if the table has an entry with aircraft and isnull(airlinedesignator) and isnull(airport) matched then
return that entry for MGT
Elseif
return the entry where all of aircrafttype, airlinedesignator and Airport are null
I can and am doing this with a hierarchical Dlookup:
Mgtvalue = Nz(dlookup("MGT", "SCH_MGT", "all 3 criteria"), Nz(dlookup("MGT", "SCH_MGT", "2 criteria plus Airport is null"), Nz(dlookup("MGT", SCH_MGT", "1 criterion plus airline is null plus airport is null"),dlookup("MGT", "SCH_MGT", "all are null"))))
this sort of works but is horribly slow if I want to use this in a query itself.
Can somebody helpme, how I can formulate a decent subquery SQL to do the same trick: basically create a query which returns exactly one MGT, depending on the selection of the above 3 criteria, and assuming that the underlying SCH_MGT table has at least an entry will criteria set to Null, which is the ultimate fallback.
Many thanks
Jan