Instagram
youtube
Facebook
Twitter

MS SQL Server BETWEEN Operator

MS SQL Server BETWEEN Operator

  • Between Operator is used to fetch data between specified range using SELECT, UPDATE, INSERT or DELETE statement.
  • Syntax:
expression BETWEEN value1 AND Value2
  • The expression indicates the column and calculations.
  • Value 1 and Value 2 indicate the lower and upper range respectively.

Example:

SELECT * FROM [University].[dbo].[Student] WHERE Age BETWEEN 18 AND 20;

or

SELECT * FROM [University].[dbo].[Student] WHERE Age>=18 AND Age<= 20;
Id Name Branch CGPA Age
EN19CS301254 Ravi CSE 9.86 19 
EN19CS301246 Savi CSE 9.23 18
EN19CS301248 Aayush CSE 7.25 20
EN19CS301258 Kavi CSE 7.50 19

BETWEEN Operator with NOT Operator

 Example:

SELECT * FROM [University].[dbo].[Student] WHERE Age NOT BETWEEN 18 AND 19;

or

SELECT * FROM [University].[dbo].[Student] WHERE Age<18 AND Age> 20;
Id Name Branch CGPA Age
EN19CS301248 Aayush CSE 7.25 20
EN19CS301258 Kavi CSE 7.50 21