Shane O’Neill explains what SARGable means and why it’s important:
So now that 1). we have our table and b). we have an index we can use, we can run the developer’s query and be SARGable right?
123DECLARE@YearINT= 2016;SELECT[Test_Date]FROM[dbo].[DateTest]WHEREYEAR([Test_Date]) = @Year;GONope! Table scan, ignores our Index and reads all 15M (too lazy for all the zeros) for a measely 127,782 rows! It’s not the slowest, taking around 3.960 seconds but still, we want SARGable!!!
Watch for the surprise twist at the end.