andyrobins
Technical User
We are currently having an issue with using sp_executesql. When you run a basic query such as
select top 1000 * from <table> where surname like 'Smith%' it returns in 14ms as you would expect. Now, as was advised on many sites, if this query is going to be reused on a regular basis but with just the search string changing then wrapping it in a sp_executesql is advised to gain a performance benefit. However.....
When you run exec sp_executesql N'select top 1000 * from <table> where surname like @surname', N'@surname varchar(8)', @surname = 'Smith%' the statement takes 40-60 seconds! Not quite the performance benefit I was expecting...
Is this supposed to be like this, or does anyone have any idea why this is so slow?
Thanks in advance
Andy
select top 1000 * from <table> where surname like 'Smith%' it returns in 14ms as you would expect. Now, as was advised on many sites, if this query is going to be reused on a regular basis but with just the search string changing then wrapping it in a sp_executesql is advised to gain a performance benefit. However.....
When you run exec sp_executesql N'select top 1000 * from <table> where surname like @surname', N'@surname varchar(8)', @surname = 'Smith%' the statement takes 40-60 seconds! Not quite the performance benefit I was expecting...
Is this supposed to be like this, or does anyone have any idea why this is so slow?
Thanks in advance
Andy