Community / Content » My · Videos · Forums · Wiki ·

Token: IIF (Inline or Immediate If)

By

January 29, 2010

IIF (Inline or Immediate If) provides the ability to utilize inline conditional checking within your queries and formatting to support nearly any requirement specified.  Sometimes, it's necessary to have conditions directly in your list.  Perhaps you want to show a column only if the record meets a certain criteria.  Using simple Boolean logic, the IIF statement will render one string if the condition is true and the other string if false.  IIF can be used in any of the rendering areas or in the query itself.

Tip: You can never go wrong with quotes.  They really help in developing more complex statements.  Also, don't forget about the escape (\) character.

 Syntax

The syntax is fairly straightforward.  Ensure that your Boolean formula is solvable; that is, a value can be determined no matter what other conditions are true.

IIF Syntax:
{IIF,"Condition",TrueText,FalseText}

<span>Your permissions are {IIF,"[RoleID,Session]=2 AND [UserID,System]=1","<b>Sufficient</b>","<b>Insufficient</b>"}
</span>         

SELECT Person.* FROM Person LEFT JOIN PersonAddress ON Person.PersonID = PersonAddress.PersonID




         WHERE Person.LastName LIKE '[Filter_LastName]' AND {IIF,"'[Filter_State]'<>''","PersonAddress.State='[Filter_State]'","1=1"}             



Condition
This is a true / false statement used to determine which string to render.  All column values are available for use. Additionally, the condition supports the complete MATH library, as well as compound statements.

Because of the utilization of the Double Quotes within the tag structures, it is recommended that string comparisons, like ‘This’=’That’ be placed within single quotes within your content. Although this is not entirely required, it does provide the ability to easily compare two terms which might be confused as another data type by the mathematics engine. 

TrueText
The second parameter, know as TrueText, of the IIF statement contains the resulting value of your IIF condition IF the condition results in a True value. This can be a simple statement or something very complex, so whenever the content must contain either other OpenWebStudio tags, or possibly double quotes you must be sure to ESCAPE the key symbols contained within – please review the next section, labeled “Escaping” for instructions and samples.

FalseText
The third parameter, know as FalseText, of the IIF statement contains the resulting value of your IIF condition IF the condition results in a False value. This can be a simple statement or something very complex, so whenever the content must contain either other OpenWebStudio tags, or possibly double quotes you must be sure to ESCAPE the key symbols contained within – please review the next section, labeled “Escaping” for instructions and samples.

Note: Be sure to enclose HTML tags in quotes (") and escape keywords that should not be evaluated.

Average ( Ratings):