I wonder if there is any wise way to rewrite the following query so that the indexes on columns get used by optimizer?
MSSQL 2008 has optimization syntax of condition simplification, here it is
Where (@key1 =0 OR Key1 =@Key1) AND (@key2 =0 OR Key2 =@Key2) option(recompile)
This will optimize usage of constants