I am having a hard time understanding why my query takes too long when using like button using parameter. but when I hard code it it just takes 5 sec to execute but if using a parameter it takes too long 5 mins still not finished this is the query of the hard coded value.
select list, useralph26, count(*) total
from sgmc.q9a_p_sot sot (nolock), sgmc.q9a_p_cot cot
where sot.record_id = cot.record_id
and suppression = 'NOT'
and response like '20180506%'
group by useralph26, list
order by list, useralph26
This query just runs fast just 5 secs
but when using parameter like I will show my query below
DECLARE @Rundate as datetime = '05/06/2018'
declare @tdate varchar(09);
--SET @tdate = '20180506%'
SELECT @tdate = CONVERT(varchar,@Rundate,112)
select list, useralph26, count(*) total
from sgmc.q9a_p_sot sot (nolock), sgmc.q9a_p_cot cot
where sot.record_id = cot.record_id
and suppression = 'NOT'
and response like @tdate + '%'
group by useralph26, list
order by list, useralph26
This query running like forever I can't understand whats wrong The query results of response column is like this
20180506 AA E ER