I had a problem with MS SQL Server 2008, which:
When I execute a query using a hard-coded string as a parameter, my query is fast, but when I use a string parameter, the query takes longer!
A constant string query takes 1 second and another 11 seconds.
Here are the codes below:
Permanent line (1 second):
SELECT * FROM VIEWCONTENTS WHERE COUNTRY = 'ZA' AND CONTENTTYPE = 'A' AND TASK = 'R23562';
Parameterized (11 seconds):
DECLARE @country AS CHAR(2); SET @country = 'ZA'; SELECT * FROM VIEWCONTENTS WHERE COUNTRY = @country AND CONTENTTYPE = 'A' AND TASK = 'R23562'
source share