I have the following SQL query which takes more time to run, i.e. more that 4 minutes to execute while executing the same query with static '1' or '0' value takes much less time, i.e. less than 3-4 seconds:
select
column1, column2
from
tablename
where
bitColumn_1 = (case when @bitColumn_1_param is null
then bitColumn_1
else @bitColumn_1_param
end)
and bitColumn_2 = (case when @bitColumn_2_param is null
then bitColumn_2
else @bitColumn_2_param
end)
and bitColumn_3 = (case when @bitColumn_3_param is null
then bitColumn_3
else @bitColumn_3_param
end)
and bitColumn_4 = (case when @bitColumn_4_param is null
then bitColumn_4
else @bitColumn_4_param
end)
and bitColumn_5 = (case when @bitColumn_5_param is null
then bitColumn_5
else @bitColumn_5_param
end)
and bitColumn_6 = (case when @bitColumn_6_param is null
then bitColumn_6
else @bitColumn_6_param
end)
and bitColumn_7 = (case when @bitColumn_7_param is null
then bitColumn_7
else @bitColumn_7_param
end)
Any help in improving the query would be helpful!
Thanks in advance