Question : Multiple conditions in IIF and dealing with 0 or NULL

I am planning multiple stretch flights from point of dept eg EHAM via  OEDF to OTBD and back.
The alternates are predetermined and have a fixed order and are retrieved via a query. Fixed alternates for OEDF are eg        OBBI
                                        OTBD
                                        OERK
                                        OKBK
It means when the destination is OEDF either coming from EHAM or OTBD the alternates will always be the same.

For commercial reasons however it was decided to give the alternates a qualifier for example,
C1 for first commercial alternate C2 for second and so on. To make life a bit more complicated the qualifiers differ for inbound from EHAM and inbound from OTBD. The list looks as follows.
                        OBBI  C2/C1
                        OTBD C1/C2
                        OERK
                        OKBK     /C3
To make the selection inbound and outbound possible I wrote for the first alternate in the query field Q1
Q1:IIf([stndata.q1] Is Null;Null;IIf([STNDATA_1.icao]=”EHAM”;Left(stndata.q1];2);Right(“00000” & [stndata.q1];2))) for flights departing EHAM. Left 2 figures for outbound EHAM en right 2 figures for inbound OEDF. There will be a problem doing this for the 4th alternate since there is no left figure so that will be my first question.

The second problem I am facing is the fact that the inbound flights to EHAM are having different
qualifiers as well but now the difference is made between narrowbody and widebody.
I read on the experts-exchange  site it was possible to extent the value_if_false  from the standard IIf(condition, value_if_true, value_if_false)  by another IIf.
I did this

Q1: IIF([stndata.q1] Is Null;Null;IIf([STNDATA_1.icao]=”EHAM”;Left([stndata.q1];2);IIF(Left$([ACSUBT];2)=”73”;Right(“00000” & [stndata.q1];2;Left([stndata.q1];2)))) where left is for the narrowbody and right for the widebody.
By doing this I miss out on the original Right(“00000”& [stndata.q1];2. This would be the second question.
Maybe I should start by pulling apart the different conditions at the first place by a different query.

Any help on missing out the inbound qualifier from OBBI and to tackle the problem in case there are no lefthand figures would be highly appreciated.
I understand it looks like a puzzle looking at it for the first time. I will try to elaborate on things if they might need clarification.

Answer : Multiple conditions in IIF and dealing with 0 or NULL

You can "nest" IIF statements. IIF statements have "TruePart" and a "FalsePart"; you can add another IIF to one of those (generally the FalsePart):

IIF("SomeValue=2", DoSomething, IIF("SomeOtherValue=3", SecondTruePart))

Note that when dealing with IIF, BOTH parts are evaluated, therefore if you have an expression that evaluates to something invalid, you'll get an error.

It would seem, however, that with a properly structred databse you could get this information without nested IIFs ...
Random Solutions  
 
programming4us programming4us