I have the below select statement from a stored procedure:
ALTER PROCEDURE [dbo].[Test]
--Params
@SolutionId INT
,@APIKey varbinary(256)
AS
SELECT
SK.SolutionID
,SK.APIKey
,SK.Enabled
FROM
dbo.SolutionKey SK
WHERE
SK.SolutionID = @SolutionId
AND SK.APIKey = @APIKey
AND Enabled = 1
The issue is that SK.APIKey
is a varbinary
datatype but in the stored procedure from the code it is passed on as 'sampledata' and so I get the error
Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query.
Can someone please tell me how can I resolve this?
Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query. The problem is that the query plan hashes are already in binary format, however stored as VARCHAR in the XML Query Plan e.g.
varbinary [ ( n | max ) ]Variable-length binary data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes. The data that is entered can be 0 bytes in length.
Something like this might work.
ALTER PROCEDURE [dbo].[Test]
--Params
@SolutionId INT
,@APIKey varchar(256)
AS
SELECT
SK.SolutionID
,SK.APIKey
,SK.Enabled
FROM dbo.SolutionKey SK
where SK.SolutionID = @SolutionId
And SK.APIKey = CONVERT(VARBINARY(256), @APIKey, 1)
And Enabled = 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With