If I have a filtered index, what do I need to have in my query to make SQL use it?

Published On: 2015-01-07By:

Filtered indexes are great, because they let you exclude rows from the index. But what do you need to include in your where clause to use the filtered index?

The answer here is surprisingly straight forward. You need to use the exact same where clause value in your queries where clause as is in the definition of the index. You also need that part of the where clause to be a text string in the query, not a parameter.

So for example “WHERE Active=1” will work, where “WHERE Active=@Active” won’t. The reason for this is that at compile time the SQL Server won’t know what the value within the @Active parameter is, so it can’t use the filtered index. It has to do this because you could pass in 0 to the @Active parameter and then the plan with the filtered index wouldn’t be valid.


Contact the Author | Contact DCAC


Globally Recognized Expertise

As Microsoft MVP’s and Partners as well as VMware experts, we are summoned by companies all over the world to fine-tune and problem-solve the most difficult architecture, infrastructure and network challenges.

And sometimes we’re asked to share what we did, at events like Microsoft’s PASS Summit 2015.

Awards & Certifications

Microsoft Partner   Denny Cherry & Associates Consulting LLC BBB Business Review    Microsoft MVP    Microsoft Certified Master VMWare vExpert
INC 5000 Award for 2020    American Business Awards People's Choice    American Business Awards Gold Award    American Business Awards Silver Award    FT Americas’ Fastest Growing Companies 2020   
Best Full-Service Cloud Technology Consulting Company       Insights Sccess Award    Technology Headlines Award    Golden Bridge Gold Award    CIO Review Top 20 Azure Solutions Providers
Share via
Copy link