Using Logical Operators and Parentheses

From AgileApps Support Wiki
Revision as of 18:19, 10 June 2011 by imported>Aeric

Logical operators combine subexpressions into a larger expression, to specify multiple conditions and complex criteria.

<subexpression1> <Logical_operator> <subexpression2>...

Logical Operators

LOGICAL_OPERATOR

Logical operators can be used to build more complex expressions.
The logical operators are:
AND
OR
Considerations
  • Two subexpressions joined by a logical operator form a logical expression.
  • Logical expressions resolve to a Boolean value: 1/0 or TRUE/FALSE.
  • Use parentheses--()--to group expressions logically and to join multiple expressions.
  • Parentheses are used in pairs; each open parenthesis "(" requires a closing parenthesis ")".
  • For example:
((<expression1> AND <expression2>) OR (<expression3> AND <expression_4>))


Use parentheses (brackets) to group expressions logically and to join one or more expressions. Parentheses are used in pairs. For each left parenthesis, there must be a right parenthesis.

((<subexpression_1> && <subexpression_2>) || <subexpression_3>) && (<subexpression_4)

Precedence

Expressions are evaluated in this order:

  1. expressions within (parentheses)
  2. expressions with && (Logical AND)
  3. expressions with || (Logical OR)
If the expression is not clearly annotated with parentheses, then && (Logical AND) takes precedence over || (Logical OR)

Examples

Expression Description
(Number of Employees <50 && Area_Code = '408') || (State = 'CA' && Industry = 'Construction' This expression finds all accounts that have fewer than 50 employees located in area code 408 or accounts in the construction industry in California
(State = 'CA') || (State = 'NV') || (State = 'WA') This expression finds all accounts where the state is either California, Nevada, or Washington
(State != 'CA') && (State != 'NV') && (State != 'WA') By contrast, this expression finds all accounts where the state is not California, Nevada, or Washington
((State = 'CA') || (State = 'NV')) && (Industry = 'Construction') This expression finds all accounts in the construction industry where the state is California or Nevada
State = 'CA' || State = 'NV' && Industry = 'Construction' Taking the example from above, but removing the parentheses finds accounts in the State of California or accounts in construction in the state of Nevada
State = 'CA' || (State = 'NV' && Industry = 'Construction') Note that the AND (&&) operator implies parentheses
contains(Acct_Name, 'Equipment') && (state = 'CA' || state ='TX') This expression finds accounts in California or Texas where the account name contains "Equipment"
contains(Acct_Name, 'Equipment') && (state = 'CA') || state ='TX' This expression finds accounts in California where the account name contains "Equipment", or any record in Texas.