# Connections with Boolean operators

Building Boolean expressions with a single test at a time can prove a bit cumbersome. You might need to combine more than one test to determine what you want. You accomplish this using Boolean operators. A Boolean operator does nothing more than connect two or more Boolean expressions to represent a true or false value.

You can choose among four Boolean operators in DML expressions: and, or, xor and not.

The and operator combines two Boolean expressions. It can represent a true value only if both left and right expressions that it connects also are true. To show how the and operator works, people that work with computers similar to draw something they call a truth table, which tells you what the result of the connected expressions is. The following is the truth table for the and operator:

Value of
left
Value of
right
Value of
left and right

False

False

False

True

False

True

False

False

True

True

The or operator links two Boolean expressions but produces a true value if either Boolean expression on left or right represents a true value. This operator can produce a false value only if both of its operands are also false.

The following is the truth table for the or operator:

Value of
left
Value of
right
Value of
left or right

False

False

False

True

True

True

False

True

True

True

The and and or operators have a close relationship to common sense. Asking yourself questions similar to Do I store the meat I’ve just bought in the fridge or the freezer?, that involve the words and or or, are quite the same as using the operators in expressions.

The xor operator connects two Boolean expressions and returns true if one and only one of the expressions it connects is true. It is just similar to the or operator except that having two true means false:

Value of
left
Value of
right
Value of
left xor right

False

False

False

True

True

True

False

True

True

False

The last Boolean operator operates only on one Boolean expression. With the not operator you can reverse the value of a Boolean expression. This means that the resulting value is false if the original was true, and true if the original was false.

With Boolean operators you can connect single tests to build bigger expressions that turn true or false in complex situations. Just similar to +, -, * and / operators in a math formula, and, or, xor and not can be used as many as needed to match the correct situation. The following is the complete expression that detects whether a year is a leap year:

 (remainder(%year, 4) = 0) and not(remainder(%year, 100) = 0)or (remainder(%year, 400) = 0)

This expression evaluates to true only when the year is a multiple of four without being a century, except for centuries that are multiples of four hundred –the remainder function is used to determine whether a year is a multiple of 4, 100 or 400.

When performing this expression, the integration engine first evaluates the expression to which the not operator is applied, then it connects the results with the and operator, and, finally computes the or of the result with the last part of the expression. Similar to basic math operators, the order of evaluating Boolean operators is strictly ruled by priority order:

 Highest priority   processed first not and xor or Lowest priority   processed last