I'm filtering a table depending on if a variable is set or not. But the clustered index is not used. Is it possible to get the query to somehow use the index. (I cant dynamically create the query in this case)
DECLARE @UseFilter as bit = 1
select pkEventId from EventEvent
where pkEventID = 57637 or @UseFilter = 0
Execution plan (not using index)
If I skip the Or
the index is used.
select pkEventId from EventEvent
where pkEventID = 57637
Execution plan (Using index)