Friday, September 11, 2015

Retrieving Records That Contain Values in a Given Range

Retrieving Records That Contain Values in a Given Range

 Range operators retrieve data based on a range. The syntax for using range operators in the SELECT statement is: SELECT column_list FROM table_name WHERE expression1 range_operator expression2 AND expression3 where, expression1 , expression2 , and expression3 are any valid combination of constants, variables, functions, or column
-
based expressions. range_operator is any valid range operator. Range operators are of the following types:


BETWEEN : 

Specifies an inclusive range to search. The following SQL query retrieves records from the Employee table where the number of hours that the employees can avail to go on a vacation is between 20 and 50: SELECT EmployeeID, VacationHours FROM HumanResources.Employee WHERE VacationHours BETWEEN 20 AND 50

NOT BETWEEN : 

Excludes the specified range from the result set. The following SQL query retrieves records from the Employee table where the number of hours that the employees can avail to go on a vacation is not between 40 and 50: SELECT EmployeeID,VacationHours FROM HumanResources.Employee WHERE VacationHours NOT BETWEEN 40 AND 50

No comments:

Post a Comment