Determines whether the value of an expression falls within a specified range of values. You can use this operator within SQL statements (SQL string/statement: An expression that defines an SQL command, such as SELECT, UPDATE, or DELETE, and includes clauses such as WHERE and ORDER BY. SQL strings/statements are typically used in queries and in aggregate functions.).
Syntax
expr [Not] Between value1 And value2
The Between...And operator syntax has these parts:
| Part |
Description |
| expr |
Expression identifying the field that contains the data you want to evaluate. |
| value1, value2 |
Expressions against which you want to evaluate expr. |
Remarks
If the value of expr is between value1 and value2 (inclusive), the Between...And operator returns True; otherwise, it returns False. You can include the Not logical operator to evaluate the opposite condition (that is, whether expr lies outside the range defined by value1 and value2).
You might use Between...And to determine whether the value of a field falls within a specified numeric range. The following example determines whether an order was shipped to a location within a range of postal codes. If the postal code is between 98101 and 98199, the IIf function returns “Local”. Otherwise, it returns “Nonlocal”.
SELECT IIf(PostalCode Between 98101 And 98199, “Local”, “Nonlocal”) FROM PublishersIf expr, value1, or value2 is Null (Null: A value you can enter in a field or use in expressions or queries to indicate missing or unknown data. In Visual Basic, the Null keyword indicates a Null value. Some fields, such as primary key fields, can't contain a Null value.), Between...And returns a Null value.
Because wildcard characters (wildcard characters: Characters used in queries and expressions to include all records, file names, or other items that begin with specific characters or that match a certain pattern.) , such as *, are treated as literals, you cannot use them with the Between...And operator. For example, you cannot use 980* and 989* to find all postal codes that start with 980 to 989. Instead, you have two alternatives for accomplishing this. You can add an expression to the query that takes the left three characters of the text field and use Between...And on those characters. Or you can pad the high and low values with extra characters — in this case, 98000 to 98999, or 98000 to 98999 – 9999 if using extended postal codes. (You must omit the – 0000 from the low values because otherwise 98000 is dropped if some postal codes have extended sections and others do not.)