WHERE Filters
Common predicates, BETWEEN/IN/LIKE/IS NULL and sargability notes.
What you’ll learn
- Common predicates:
=
,<>
,BETWEEN
,IN
,LIKE
,IS NULL
. - Sargability basics (avoid wrapping indexed columns).
SELECT *
FROM dbo.Products
WHERE Price BETWEEN 10 AND 20
AND CategoryID IN (1,2,3)
AND Discontinued = 0
AND Name LIKE N'%Widget%'
AND Color IS NOT NULL;
Notes
LIKE '%prefix%'
disables seeks; tryLIKE N'prefix%'
when possible.- Avoid
WHERE YEAR(OrderDate)=2025
; preferOrderDate >= '2025-01-01' AND OrderDate < '2026-01-01'
.