[NOT] BETWEEN (TSQL Operator)

Checks if the value of an expression is inside the specified boundaries.

Syntax

expression [ NOT ] BETWEEN start_expr AND end_expr

Arguments

expression
is an expression of any type.
start_expr
is an expression of any type.
end_expr
is an expression of any type.

Return Types

Returns a result of type bool.

Remarks

BETWEEN returns True if expression is >= start_expr and <= end_expr.

In fact, expr BETWEEN a AND b is exactly the same as expr >= a AND expr <= b.

If expression, start_expr and end_expr are varchar, the comparison is affected by the collation.

NOT BETWEEN returns the negated result of BETWEEN.

Examples

PRINT 4    BETWEEN 5 AND 20;
PRINT 5    BETWEEN 5 AND 20;
PRINT 10   BETWEEN 5 AND 20;
PRINT 20   BETWEEN 5 AND 20;
PRINT 21   BETWEEN 5 AND 20;
PRINT NULL BETWEEN 5 AND 20;

The result is:

false
true
true
true
false
<NULL>