Skip to main content

IF

IF(expression, trueresult [, falseresult ])

expressionA conditional expression.
trueresultThe result to return when the expression is true. This may be any expression or action.
falseresultThe result to return when the expression is false. This may be any expression or action. This may be omitted only if the result is an action.
Return:IF returns a single value, set, recordset, or action.

The IF function evaluates the expression (which must be a conditional expression with a Boolean result) and returns either the trueresult or falseresult based on the evaluation of the expression. Both the trueresult and falseresult must be the same type (i.e. both strings, or both recordsets, or ...). If the trueresult and falseresult are strings, then the size of the returned string will be the size of the resultant value. If subsequent code relies on the size of the two being the same, then a type cast to the required size may be required (typically to cast an empty string to the proper size so subsequent string indexing will not fail).

Example:

MyDate := IF(ValidDate(Trades.trd_dopn),Trades.trd_dopn,0);
  // in this example, 0 is the false value and
  // Trades.trd_dopn is the True value returned

MyTrades := IF(person.per_sex = 'Male',
     Trades(trd_bal<100),
     Trades(trd_bal>1000));
  // return low balance trades for men and high balance
  // trades for women

MyAddress := IF(person.gender = 'M',
      cleanAddress182(person.address),
      (STRING182)'');
  //cleanAddress182 returns a 182-byte string
  // so casting the empty string false result to a
  // STRING182 ensures a proper-length string return

See Also: IFF, MAP, EVALUATE, CASE, CHOOSE, SET