Searching for Ranges of Values with Inequalities (>, <, BETWEEN)
SQL Server enables you to search for a range of values with greater than and less than operators, and with the BETWEEN keyword. These comparison operators work just like the equals and not equals comparison methods, so I'll just show you a couple of examples. After that, we'll look at a couple of specific issues with range searching.
SQL Server supports the four basic inequality operators: > (greater than), < (less than), >= (greater than or equals), and <= (less than or equals). All these operators work with a variety of data types (numeric, string, date, and binary). Let's start by looking at numeric comparisons.
This first query looks for products whose price is less than $7: ...
Get Sams Teach Yourself Transact-SQL in 21 Days, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.