How to Optimize the Use of the “OR” Clause When Used with Parameters (SQL Server 2008)
问题 I wonder if there is any wise way to rewrite the following query so that the indexes on columns get used by optimizer? CREATE PROCEDURE select_Proc1 @Key1 int=0, @Key2 int=0 AS BEGIN SELECT key3 FROM Or_Table WHERE (@key1 = 0 OR Key1 = @Key1) AND (@key2 = 0 OR Key2 = @Key2) END GO According to this article How to Optimize the Use of the "OR" Clause When Used with Parameters by Preethiviraj Kulasingham: Even though columns in the WHERE clauses are covered by indexes, SQL Server is unable to