The IF function provides the if-then-else/else if logic to rules. The function can take a variable number of parameters, and will behave differently based on the parameters. First, it can take a single parameter whose value is evaluated as a Boolean. If this parameter is true, the IF function will return true; otherwise it will return false. Note that this form of the function has limited use, as the condition being checked can be passed directly to what would otherwise be the caller of the IF function, without actually making the IF function call.
Second, the function can take a multiple number of parameters to provide the if-then-else/else if logic. The first parameter is a Condition parameter, and is evaluated as a Boolean. When true is returned, its corresponding Then parameter is evaluated and the resulting value is returned.
If a Condition parameter returns false, its corresponding Then parameter is not evaluated. The next Condition parameter is evaluated. A final optional parameter can be provided as the Else parameter. This parameter is evaluated when all Condition parameters have evaluated to false. The value resulting from evaluation of the Else parameter is then returned by the IF function.
All Then parameters and the Else parameter are evaluated in the context of the IF function call. The expected data type for these parameters is then the data type of that context.
- @IF (Condition
1 [,Then 1] [, ... Else If Condition N, Then N] [, Else])
- Condition 1 Required Boolean parameter, contains the value evaluated by the function to determine a return. When true, Then 1 is returned if specified. When false, either the next Else If Condition N parameter is evaluated if specified. Else is evaluated if no Else If Condition exists. The context null-equivalent is returned if neither an Else If Condition or Else parameter is provided. If Condition 1 is the only parameter, its Boolean value will be returned.
- Then 1 Optional parameter, evaluated in the context of the function call. This parameter is evaluated when Condition 1 is true. The value returned by the evaluation of Then 1 is then returned by the IF function.
- Else / Else If Condition N Optional parameter(s), evaluated when Condition 1 or the preceding Else If Condition parameter returns false. The data type for this parameter is dependent on whether it is the last parameter to the function or is followed by another parameter. If it is the last parameter, it is evaluated in the context of the function call. Its is the Else parameter to the function and will be evaluated when all preceding Condition parameters have returned false. If this parameter is not the last for the function, it is evaluated as a Boolean and is treated as an Else IF Condition N parameter. If it evaluates to true the corresponding Then N parameter will be evaluated by the function.
- Then N Optional parameter, evaluated in the context of the function call. This parameter is evaluated when its corresponding Else If Condition N parameter returns true. The value returned by the evaluation of Then N is then returned by the IF function.
Supported Return Types
- Integral Number
- Decimal Number