I'm facing a little problem in writing a stored procedure in SQL Server. When I pass global or local variable to the select query, it takes 3 minutes to execute; however, when directly passing the value instead of through a variable, it takes just 1 second.
For example:
--------this query takes 3 minutes----------------
Declare @code varchar (10)
begin
select abc
from <table>
where code = @code
end
---------------this query take 2 seconds----------
Declare @code varchar (10)
begin
select abc
from <table>
where code = 'A22'
end
Please guide/suggest me how handle this logic however I have to use first logic