Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 5: Using Operators and Expressions in Access


177


The less-than operator: <
The less-than operator (<) returns a logical True if the left side of the equation is less than the
right side, as in this example:

[tblSalesLineItems].[Price] < 1000 Returns True if the Price field con-
tains a value of less than 1,000 and
False whenever Price is greater
than 1,000.

Interestingly, the less-than operator (in fact, the same is true for most comparison operators) is eas-
ily applied to string values. For example, the following expression is False:

“Man” > “Woman”

Without getting philosophical about the expression, what actually happens is that Access does a
character-by-character comparison of the strings. Because M appears before W in the alphabet, the
word Man is not greater than Woman. The ability to compare strings can be of significant value
when sorting string data or arranging names in a particular order.

Again, because Access string comparisons are not case sensitive, XYZ is not greater than xyz.

The less-than-or-equal-to operator: <=
The less-than-or-equal-to operator (<=) returns True if the operand on the left side of the equa-
tion is either less than or equal to the right-side operand, as in this example:

[tblSalesLineItems].[Price] <= 2500 Returns True if Price equals 2500
or is less than 2500 , and False for
any Price that is more than 2500.

Caution
Comparison operators must be composed properly. Access reports an error if you enter =<. The order of the
characters in this operator is important. It must be less than or equal to: <=.


The greater-than operator: >
The greater-than operator (>) is the opposite of less than. This operator returns True when the
left-side operand is greater than the operand on the right side. For example,

[tblSales].[TaxRate] > 3.5 Returns True if TaxRate is greater than 3.5,
and False whenever TaxRate is less than or
equal to 3.5.

The greater-than-or-equal-to operator: >=
The greater-than-or-equal-to operator (>=) returns True if the left side is either greater than or
equal to the right side. For example,

[tblSales].[TaxRate] >= 5 Returns True if TaxRate is 5 or greater.
Free download pdf