0

TSQL insert into table with bulkcolumn -- needing two bulkcolumn inserts into same row

I need to run a query with two bulkcolumn inserts into the same row.

I am trying:

However, I get the error: Invalid object name 'BulkColumn' Is this just a syntax problem, or is this a more fundamental rule (such as one can only insert one bulkcolumn per statement)?

Example: in the SSMS edit-window.

INSERT INTO [table1] ([id1], [bulk1],[bulk2] 
SELECT '123',
 BulkColumn 
FROM Openrowset( Bulk 'C:\bulkDir1\a1.jpg', Single_Blob) as a1,
BulkColumn 
FROM Openrowset( Bulk 'C:\bulkDir2\b1.jpg', Single_Blob) as a2

It says (in the 'squiggly error' in the SSMS edit-window.):
Invalid object name 'BulkColumn'

JosephDoggie
  • 1,514
  • 4
  • 27
  • 57

1 Answers1

2

You can do it this way, your syntax is just a little off to get both columns:

CREATE TABLE table1(id1 nvarchar(60),   
  [bulk1] varbinary(max), [bulk2] varbinary(max));  
GO  

INSERT INTO table1([id1], [bulk1],[bulk2])   
   SELECT 
    '123' AS FileName,    
     pic1.BulkColumn ,
     pic2.BulkColumn
  FROM OPENROWSET(BULK N'C:\test\a1.jpg', SINGLE_BLOB) AS pic1
  inner join OPENROWSET(BULK N'C:\test\b1.jpg', SINGLE_BLOB) AS pic2
    on 1=1
Jesse
  • 865
  • 10
  • 18
  • This definitely works -- people may also wish to see: https://stackoverflow.com/questions/3306096/combining-insert-into-and-with-cte – JosephDoggie Aug 09 '17 at 18:07