gotchasqlMinor
Unexpected Implicit conversion in a procedure
Viewed 0 times
implicitconversionunexpectedprocedure
Problem
I have a procedure like this (simplified):
There is a non-clustered index on Username column of the Member table.
Plan cache shows an Implicit Conversion as such:
Seek Keys[1]: Prefix: [MyDatabase].[dbo].[Member].Username = Scalar
Operator(CONVERT_IMPLICIT(varchar(64),[@Username],0))
I was just wondering what might be causing this implicit conversion as both the parameter and the field data type "UserName" is varchar(64)?
SP is called from framework like this:
Thank you.
CREATE PROCEDURE test @userName VARCHAR(64)
SELECT *
FROM member M
INNER JOIN order O
ON M.MemberId=O.MemberId
WHERE M.Username = @userNameThere is a non-clustered index on Username column of the Member table.
Plan cache shows an Implicit Conversion as such:
Seek Keys[1]: Prefix: [MyDatabase].[dbo].[Member].Username = Scalar
Operator(CONVERT_IMPLICIT(varchar(64),[@Username],0))
I was just wondering what might be causing this implicit conversion as both the parameter and the field data type "UserName" is varchar(64)?
SP is called from framework like this:
EXEC test @Username=N'webSite.com'Thank you.
Solution
It was all down to collation of the column. It was different from the database's (and the table's) collation. Now changed the column's collation to database's and no more implicit conversion shows up. Have no idea about the internals and why it caused the problem.
Context
StackExchange Database Administrators Q#97171, answer score: 6
Revisions (0)
No revisions yet.