Difference between revisions of "Using Logical Operators and Parentheses"
From LongJump Support Wiki
imported>Aeric |
imported>Aeric |
||
Line 17: | Line 17: | ||
::''If the expression is not clearly annotated with parentheses, then <tt>&&</tt> (Logical AND) takes precedence over <tt>||</tt> (Logical OR)'' | ::''If the expression is not clearly annotated with parentheses, then <tt>&&</tt> (Logical AND) takes precedence over <tt>||</tt> (Logical OR)'' | ||
===Examples=== | |||
{| border="1" cellpadding="5" cellspacing="0" | {| border="1" cellpadding="5" cellspacing="0" |
Revision as of 18:17, 10 June 2011
Boolean operators are used to build subexpressions within an expression, resulting in the ability to create multiple conditions and complex criteria.
<subexpression1> <Boolean_operator> <subexpression2>...
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:
- expressions within (parentheses)
- expressions with && (Logical AND)
- 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. |