0

I'm trying to add an img from my own computer for testing and I need to upload an img or pdf to a column in SQL Server as a varbinary data type. the table has 6 columns; description, img, date, etc.. how do I upload the img or pdf when I have more columns to fill?

create table testVarBinary (description nchar(10), img varbinary(max), etc..)

insert into testVarBinary 
SELECT BulkColumn
FROM OPENROWSET (BULK 'FullFilePath\\FileName.pdf', SINGLE_BLOB) as img

I know this works for the img but how do I fill the other columns?

this is just an example, some data may not be correct like the syntax.

  • 1
    Have you tried something like `insert ... SELECT @description, BulkColumn, @etc, ... FROM ...` where @description and @etc are variables containing the desired values? – T N Mar 30 '22 at 16:04
  • See [this example](https://learn.microsoft.com/en-us/sql/t-sql/functions/openrowset-transact-sql?view=sql-server-ver15#d-using-openrowset-to-bulk-insert-file-data-into-a-varbinarymax-column). (I would replace the `*` in the example with the explicit column reference `BulkColumn`.) – T N Mar 30 '22 at 16:12
  • ok, i will try with that example. – Elvin Castillo Mar 30 '22 at 16:21
  • please, please do not store images or pdfs inside the database. – Brian Stork Mar 30 '22 at 16:54
  • this is a solution for a company that wants that additional security layer and that's the way how their DB is built I am just building a web app to pull this information and display it in a view. – Elvin Castillo Mar 30 '22 at 17:14
  • @BrianStork - Why not? I know there may be many reasons not to (such as the ability to use external tools to search and index content), but is it a hard fast rule? – T N Mar 31 '22 at 18:18

0 Answers0