sql server - Inserting a pdf file to SQL table using SQL -


i trying insert pdf file sql table (varbinary column)

create table pdftest(pdfdata varbinary(max)) declare @filepath varchar(100) set @filepath = 'c:\pdfsample.pdf' insert pdftest (pdfdata) select * openrowset(bulk @filepath, single_blob) blob 

however gives error

 incorrect syntax near '@filepath'. 

none of following assignment works

 set @filepath = 'c:'\pdfsample.pdf'  set @filepath = 'c:\\pdfsample.pdf' 

but following syntax works

 insert pdftest (pdfdata) select * openrowset(bulk 'c:\pdfsample.pdf', single_blob) blob 

just wondering how @filepath can used in insert statement?

thank you

i think here variable name not getting resolved. try using variable name in dynamic sql.

 declare @sql varchar(max)  set @sql='insert pdftest (pdfdata) select * openrowset(bulk'+ @filepath+', single_blob) blob'  exec @sql 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -