Friday, 3 April 2015

SQL Server BETWEEN Operator

BETWEEN: Specifies a range to test.

Example: - With Numeric
SELECT * FROM employees WHERE employee_id BETWEEN 25 AND 100;
This SQL Server BETWEEN example would return all rows from the employees table where the employee_id is between 25 and 100.

It is equivalent to the following SELECT statement:
SELECT * FROM employees WHERE employee_id >= 25
AND employee_id <= 100;

Example: - With Date
SELECT * FROM employees WHERE start_date BETWEEN '2015/03/01' AND '2015/03/31';
This SQL Server BETWEEN condition example would return all records from the employees table where the start_date is between March 1, 2015 and March 31, 2015.

Example: - Using NOT Operator
SELECT * FROM employees WHERE employee_id NOT BETWEEN 2000 AND 2999;

This SQL Server BETWEEN example would return all rows from the employees table where the employee_id was NOT between 2000 and 2900.

Queries :

1. Write a Query to get employee details  from employee table whose salary between 5000 and 10000.

Ans: Select * from employee where salary between 5000 and 10000.

No comments:

Post a Comment