August 27th, 2008

BETWEEN (Matching to a Range)

Posted by admin in D. WHERE Clause

BETWEEN determines if a test column value falls within a specified range.

SELECT column1, column2, ...
  FROM table1, table2, ...
 WHERE testcolumn [NOT] BETWEEN lowvalue AND highvalue, ...;

> BETWEEN is the same as saying WHERE (testcolumn >= lowvalue) AND (testvalue <= highvalue).
> BETWEEN works with numbers, datetimes, character strings and expressions.
> Character string comparisons are case sensitive or insensitive depending on your DBMS.
> The first value must be lower than (or equal to) the second value separated by the word AND.
> The low value and the high value are included in the search results.
> You can reverse the selected values with NOT BETWEEN.
> You can combine BETWEEN with other conditions using AND and OR.
> The testcolumn does not have to be one of the columns you SELECT.
> If the testcolumn value is a NULL and meets the NOT BETWEEN, then the returned value is NULL.

Note: Access surrounds a date with the # symbol, such as #2050-01-01#.
DB2 and SQL Server surround the date with the single quote symbol (‘), and they omit the DATE key word. Example: ’2050-01-01′ instead of DATE ’2050-01-01′.

Comments are closed.

Sorry, the comment form is closed at this time.