• 13. 1. 2020
  • Ing. Jan Zedníček - Data Engineer & Controlling
  • 0

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

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

My name is Jan Zedníček and I have been working as a freelancer for many companies for more than 10 years. I used to work as a financial controller, analyst and manager at many different companies in field of banking and manufacturing. When I am not at work, I like playing volleyball, chess, doing a workout in the gym.

🔥 If you found this article helpful, please share it or mention me on your website

Leave a Reply

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