Partilhar via


IIF( ) Function

Returns one of two values depending on the value of a logical expression.

IIF(lExpression, eExpression1, eExpression2)

Return Values

Character, Numeric, Currency, Date, or DateTime

Parameters

  • lExpression
    Specifies the logical expression that IIF( ) evaluates.
  • eExpression1, eExpression2
    If lExpression evaluates to true (.T.), eExpression1 is returned. If lExpression evaluates to false (.F.), eExpression2 is returned.

Remarks

This function, also known as Immediate IF, evaluates a logical expression and then returns one of two expressions. If the logical expression evaluates to true (.T.), IIF( ) returns the first expression. If the logical expression evaluates to false (.F.), IIF( ) returns the second expression.

Tip   This function can be used in place of IF ... ENDIF for simple conditional expressions, and is especially useful in report and label expressions that conditionally specify field contents. The IIF( ) function also executes faster than an equivalent IF ... ENDIF.

Example

The following example uses IIF( ) to check if the notes field in the employee table is empty. If it is empty, "No description" is displayed; otherwise, the contents of the memo field are displayed.

CLOSE DATABASES
OPEN DATABASE (HOME(2) + 'Data\testdata')
USE employee  && Open Employee table
CLEAR

SCAN
   ? IIF(EMPTY(notes), 'No notes', notes)    && Empty memo field?
ENDSCAN

See Also

IF ... ENDIF | #IF ... #ENDIF Preprocessor Directive | IF Statements