JavaScript Editor js editor     Web development 



Main Page

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

IIF(lExpression, eExpression1, eExpression2)

Parameters

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

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.) or null (.NULL.), 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.

В Copy Code
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



JavaScript Editor js editor     Web development