Token: IIF (Inline or Immediate If)

By

January 29, 2010

IIF (Inline or Immediate If) provides 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 certain criteria.  Using simple Boolean logic, the IIF statement will render one string when the condition evaluates to true and the other string when the condition evaluates to false.  IIF can be used in any 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. 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, TrueText, specifies the text that will be rendered when Condition evaluates to true. This can be a simple statement or something very complex. When TrueText contains either other OpenWebStudio tags, or possibly double quotes you should ESCAPE the key symbols contained within – please review the next section, labeled “Escaping” for instructions and examples.

FalseText
The third parameter, FalseText, specifies the text that will be rendered when Condition evaluates to false.  This can be a simple statement or something very complex. When FalseText contain either other OpenWebStudio tags, or possibly double quotes you shuld 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):
 
Want to help out?
 
 

New York, NY • Baltimore, MD • Vienna, VA • St. Louis, MO • Seattle, WA • info@openwebstudio.com

Bookmark & Share Bookmark and Share