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.
|