BETWEEN in SQL Server

BETWEEN Operator is used to retrieve data with in the range of values mentioned in BETWEEN operator.

Generally BETWEEN Operator is used in the WHERE Clause to compare fetch the records with in certain range.

Syntax for BETWEEN operator will be as follows:

BETWEEN <value 1> and  <value 2>

Example:

Lets retrieve the orders from MYORDERS table whose OrderId is between 100001 and 100004.

Query for the above requirement would be:

SELECT * FROM MYORDERS WHERE OrderId BETWEEN 100001 and 100004

Result set for the above Query will be:











From the above result set it is evident that Between will consider both the boundary values also into account which returning the data.

That is,

{column A} BETWEEN {value1} AND {value2}

will be considered as :

{column A} >= {value1}  AND
{column A} <= {value2} 

Note: BETWEEN Operators considers boundary values also into account which returning data.

This entry was posted in . Bookmark the permalink.

Leave a reply