1

I'm trying to insert data in next table: Table Of Data

I'm using Management Studio, but i don't know how to relate the file inserted with the column which has the ID number (in my case is named 'Batch'). All examples that I've found are like this without that column :

CREATE TABLE nameTable(fileReport varbinary(max)) 
INSERT INTO nameTable (fileReport) SELECT * FROM OPENROWSET(BULK 'c:\File1.pdf', SINGLE_BLOB) AS BLOB
  • I tried reformatting your SQL to make it a bit easier to read but I cannot tell if that second line (staring with `{INSERT INTO` should be two lines or one. – Onorio Catenacci Oct 24 '19 at 17:02
  • I re-edit the question, look at it – Robinson Mira Oct 24 '19 at 17:12
  • Have you seen this [Q & A](https://stackoverflow.com/questions/1643627/how-to-insert-a-blob-into-a-database-using-sql-server-management-studio)? I think it may address your question. – Onorio Catenacci Oct 24 '19 at 17:16
  • Oh and make sure that file path you're specifying (in `OPENROWSET`) is a file path on _the_ _server_ not your client. – Onorio Catenacci Oct 24 '19 at 17:21
  • Yes Onorio, it is in the server. the problem is that I don't know what is the syntax to add the other data, because it creates a table with one column. I tried many ways and there is always a mistake. I'm going to check Q & A – Robinson Mira Oct 24 '19 at 18:17

1 Answers1

1

Ok, if I understand your question correctly the answer would be something like this:

INSERT INTO nametable
            (batch,
             filereport)
VALUES      ('batch_number1',
             (SELECT *
              FROM   OPENROWSET(BULK 'c:\File1.pdf', single_blob) AS fileReport)
)  

I think your issue is that you're not doing the VALUES clause on your INSERT statement

By the way, credit where it's due; I got that answer from this web page

Onorio Catenacci
  • 14,928
  • 14
  • 81
  • 132