IIF( ) Function

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

IIF(lExpression, eExpression1, eExpression2)


  • lExpression
    Specifies the logical expression that IIF( ) evaluates.
  • eExpression1, eExpression2
    If lExpression evaluates to True (.T.), eExpression1 is returned and eExpression2 is not evaluated. If lExpression evaluates to False (.F.) or null (.NULL.), eExpression2 is returned and eExpression1 is not evaluated.

Return Value

Character, Numeric, Currency, Date, or DateTime


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.) or null (.NULL.), IIF( ) returns the second expression.


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.


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.

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

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

See Also


IF ... ENDIF Command
#IF ... #ENDIF Preprocessor Directive
IF Statements
ICASE( ) Function

Other Resources

Language Reference (Visual FoxPro)