The function evaluates its condition as a Boolean. If the result is TRUE, it returns the value of expression1; otherwise, it returns the value of expression2.
Prior to using IIf, please read the Usage section carefully.
IIf(condition, string_expression1, string_expression2)
Any expression that can be evaluated as a Boolean.
Valid expression to be evaluated and returned if condition is TRUE.
Valid expression to be evaluated and returned if condition is FALSE.
The IIf function is a shortcut for the following construct:
<CFIF condition> <CFSET result=expression1> <CFELSE> <CFSET result=expression2> </CFIF>
returning result.
<!--- This example shows IIf ---> <HTML> <HEAD> <TITLE> IIf Example </TITLE> </HEAD> <BODY bgcolor=silver> <H3>IIf Function</H3> <P>IIf evaluates a condition, then evaluates on expression 1 or expression 2 depending on the Boolean outcome <I>(TRUE=run expression 1; FALSE=run expression 2)</I>. </P> <CFSET number1=-10> <CFSET number2=2> <CFSET number3=number1 * number2> <P>The result of the expression IIf(number3 GT number1, number1 * number2, Abs(number1) * Abs(number2)) is:<BR> <CFOUTPUT> #IIf(number3 GT number1, number1 * number2, Abs(number1) * Abs(number2))# </CFOUTPUT> </P> </BODY> </HTML>