简体   繁体   English

OPENROWSET-不允许从数据类型varchar隐式转换为varbinary(max)。 使用CONVERT函数运行此查询

[英]OPENROWSET - Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query

Hi I am trying to insert results of a stored procedure into a table called MyBinaryTable. 嗨,我正在尝试将存储过程的结果插入到名为MyBinaryTable的表中。 MyBinaryTable contains two columns: (FileId [type:int], and BulkColumn [type:varbinary(max)]). MyBinaryTable包含两列:(FileId [type:int]和BulkColumn [type:varbinary(max)])。 The stored procedure returns two columns called FileId and BulkColumn. 该存储过程返回两列,分别称为FileId和BulkColumn。 When Inserting the values into MyBinaryTable from the stored procedure, I am greeted with this error: 当从存储过程中将值插入MyBinaryTable时,出现此错误:

Implicit conversion from data type varchar to varbinary(max) is not allowed. 
Use the CONVERT function to run this query.

Here is my stored procedure: 这是我的存储过程:

CREATE PROCEDURE [dbo].[GenerateBinary] @Route VARCHAR(300), @FileId 
VARCHAR(10)
AS
Declare @sql varchar(max)
Set @sql='SELECT convert(varbinary(max),((SELECT BulkColumn FROM OPENROWSET( 
BULK ''' + @Route + ''' , SINGLE_BLOB) as Data)), 0) as ''BulkColumn'',''' + 
@FileId + ''' as ''FileId'''
Print @sql
Exec(@sql)

Here is how I am inserting the values: 这是我插入值的方式:

INSERT INTO MyBinaryTable
EXEC GenerateBinary 'xyz.docx', @FileId = 254

Do not develop bad habits. 不要养成不良习惯。 You did not specify the column list in the insert statement - that is a bad habit and the cause of our error. 您没有在insert语句中指定列列表-这是一个不良习惯,也是导致我们出错的原因。 The resultset of your procedure is [varbinary(max), varchar(10)]. 该过程的结果集为[varbinary(max),varchar(10)]。 Is that the same as the structure of your table? 这与表的结构相同吗? No. And you also force another implicit conversion with your fileid argument defined as varchar. 不会。您还可以将fileid参数定义为varchar强制进行另一个隐式转换。 So change your procedure to define fileid as int and specify the columns in the insert statement: 因此,更改您的过程以将fileid定义为int并在insert语句中指定列:

insert dbo.MyBinaryTable(BulkColumn, FileId)
select ...;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 不允许从数据类型varchar(max)隐式转换为varbinary(max)。 使用CONVERT函数运行此查询 - Implicit conversion from data type varchar(max) to varbinary(max) is not allowed. Use the CONVERT function to run this query 错误:不允许从数据类型varchar到varbinary(max)的隐式转换。 使用CONVERT函数运行此查询 - Error : Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query INSERT查询错误:不允许从数据类型varchar到varbinary的隐式转换。 使用CONVERT函数运行此查询。 - INSERT query error: Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query. [SQL Server]不允许从数据类型nvarchar(max)到varbinary(max)的隐式转换。 使用CONVERT函数运行此查询 - [SQL Server]Implicit conversion from data type nvarchar(max) to varbinary(max) is not allowed. Use the CONVERT function to run this query 不允许从数据类型varchar到varbinary(max)的隐式转换。 使用CONVERT - Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT 不允许从数据类型ntext到varchar的隐式转换。 使用CONVERT函数运行此查询 - Implicit conversion from data type ntext to varchar is not allowed. Use the CONVERT function to run this query 不允许从数据类型sql_variant隐式转换为varbinary(max)。 使用CONVERT函数运行此查询。 ASP.NET SQL数据源 - Implicit conversion from data type sql_variant to varbinary(max) is not allowed. Use the CONVERT function to run this query. ASP.NET SQL DataSource 不允许从数据类型 varchar 到 varbinary 的隐式转换。 (SQL) - Implicit conversion from data type varchar to varbinary is not allowed. (SQL) 不允许从数据类型datetime到int的隐式转换错误。 使用CONVERT函数运行此查询 - Error of Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query Sql异常:不允许从数据类型datetime到int的隐式转换。 使用CONVERT函数运行此查询 - Sql Exception : Implicit conversion from data type datetime to int is not allowed. Use the CONVERT function to run this query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM