IIf(condition, string_expression1, string_expression2)
The function evaluates its condition as a Boolean. If the result is TRUE it returns the value of Evaluate(string_expression1); otherwise, it returns the value of Evaluate(string_expression2).
Any expression that can be evaluated as a Boolean.
Valid string expression to be evaluated and returned if condition is TRUE.
Valid string expression to be evaluated and returned if condition is FALSE.
The IIf function is a shortcut for the following construct:
<CFIF condition> <CFSET result=Evaluate(string_expression1)> <CFELSE> <CFSET result=Evaluate(string_expression2)> </CFIF>
returning result.
The expressions string_expression1 and string_expression2 must be string expressions, so that they do not get evaluated immediately as the arguments of IIf. For example:
IIf(y is 0, DE("Error"), x/y)
will generate error if y=0 because the third argument is the value of x/0 (not a valid expression).
Remember that ColdFusion evaluates string_expression1 and string_expression2. To return the string itself instead of evaluate the expression, use the DE (delay evaluation) function.