SQL BETWEEN Operator – Defining Range in a Condition with Examples

This operator is used in SQL whenever it is needed to prove if certain value belongs to some range. This operator is used together with “AND” command which defines given range. Operator can be used in most of the clauses but is most common in WHERE for defining limiting requirement.

SQL BETWEEN Operator Syntax

SELECT [Date]
FROM [dbo].[Table]
WHERE [Date] BETWEEN '1900-01-01' AND '2050-12-31';

Condition can be obviously defined not only by date fields but even above any data type (where it makes sense) – numeral data types, text data types etc. Boundaries of the interval are included in the requirement with this operator.

Between can be used even in negative limitation, we would use NOT BETWEEN.

T-Sql query (as in Syntax above) is equal to query below:

SELECT [Date]
FROM [dbo].[Table]
WHERE [Date] >= '1900-01-01' AND [Date] <= '2050-12-31';

BETWEEN is more elegant, shorter and makes your code clearer at a first glance. More on this operator can be accessed via this link

Rate this post
Category: SQL Operators

About Ing. Jan Zedníček - Data Engineer & Controlling

My name is Jan Zednicek, and I have been working as a freelance Data Engineer for roughly 10 years. During this time, I have been publishing case studies and technical guides on this website, targeting professionals, students, and enthusiasts interested in Data Engineering particularly on Microsoft technologies as well as corporate finance and reporting solutions. 🔥 If you found this article helpful, please share it or mention me on your website or Community forum

Leave a Reply

Your email address will not be published. Required fields are marked *