2

这些是我发现的用于插入二进制数据(使用 varbinary)的查询,它运行良好 CREATE TABLE Employees (
Id int,
Name varchar(50) not null,
Photo varbinary(max) not null
)

INSERT INTO Employees (Id, Name, Photo)
SELECT 10, 'John', BulkColumn from Openrowset( Bulk 'C:\photo.bmp', Single_Blob) as EmployeePicture

但是如果表employee有如下列怎么办:
CREATE TABLE Employees (
Id int,
Photo varbinary(max) not null,
Name varchar(50) not null
)

[Photo column is 2nd over here!]
我尝试操作插入查询但没有帮助!

4

1 回答 1

2

你会用

 INSERT INTO Employees
 SELECT 10, BulkColumn AS EmployeePicture, 'John'
 FROM OPENROWSET( BULK 'C:\photo.bmp', Single_Blob) bc

或者

 INSERT INTO Employees
 SELECT 10, 
        (SELECT BulkColumn AS EmployeePicture  FROM OPENROWSET( BULK 'C:\photo.bmp', Single_Blob) bc), 
        'John'

我想你可能正在尝试这样的事情

 INSERT INTO Employees
 SELECT 10, 
        BulkColumn AS EmployeePicture  FROM OPENROWSET( BULK 'C:\photo.bmp', Single_Blob), 
        'John'
于 2011-04-05T16:50:15.963 回答