SQL 不允许从数据类型 varchar 隐式转换为 varbinary。使用 CONVERT 函数运行此查询
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27001768/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query
提问by user505210
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
问题是这SK.APIKey
是一种varbinary
数据类型,但在代码的存储过程中它作为“sampledata”传递,所以我得到了错误
Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query.
不允许从数据类型 varchar 隐式转换为 varbinary。使用 CONVERT 函数运行此查询。
Can someone please tell me how can I resolve this?
有人可以告诉我我该如何解决这个问题?
回答by bowlturner
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