Open Blob fields using Openrowset in SQLSERVER 2008 R2

I need help reading a file from SQLServer2008 R2 using Openrowset, I can write the file in the Blob column as follows:

INSERT INTO myTable(FileName, FileType, Document) 
   SELECT 'Text1.txt' AS FileName, 
      '.txt' AS FileType, 
      * FROM OPENROWSET(BULK N'C:\Text1.txt', SINGLE_BLOB) AS Document;

but how to read it and write to disk?

Thank you

+3
source share
1 answer

You can use the bcp utility in conjunction with the query argument to save the blob to disk.

bcp "select datei 
     from   Adventureworks.Person.Address 
     WHERE  addressid=1 " 
queryout "c:\TestOut.doc" -T -n -Slocalhost

There are some good examples on the bcp page , as well as many command line options.

0
source

All Articles