Skip to content

Instantly share code, notes, and snippets.

@AlexArchive
Created July 29, 2013 14:41
Show Gist options
  • Save AlexArchive/6104780 to your computer and use it in GitHub Desktop.
Save AlexArchive/6104780 to your computer and use it in GitHub Desktop.
-- In most cases, when you apply a manipulation on the filtered
-- column, SQL Server cannot use an index in an efficient manner:
SELECT orderid, custid, empid, orderdate
FROM Sales.Orders
WHERE YEAR(orderdate) = 2007
-- To have the potentioal to use an index efficiently, you need
-- to revise the predicates so that there is no manipulation on
-- the filtered column:
SELECT orderid, custid, empid, orderdate
FROM Sales.Orders
WHERE orderdate BETWEEN '20070101' AND '20080101';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment