May 15, 2007 at 11:03 am
is there a way to retrive images from sql table to file byTSql procedure?
thank
May 16, 2007 at 1:48 am
Please don't post the same questions in multiple threads.
Sam,
Copy in
UPDATE dbo.TestData
SET binary_data = (SELECT binary_data FROM OPENROWSET(
BULK 'c:\temp\picture.jpg', SINGLE_BLOB) AS F(binary_data))
To copy the file out, before SQL2005 there existed a tool called TEXTCOPY.EXE. However this doesn’t exist anymore. I tried using SQLCMD, OSQL and BCP but each time the jpg got corrupted. At last I found that you could use a format file with BCP. This seems to work.
BCP "SELECT binary_data FROM tempdb.dbo.testdata" queryout D:\temp\test.jpg -S ServerName -T -f test.fmt
Format file contents:
9.0
1
1 SQLBINARY 0 0 "" 1 col1 ""
Of course you need to loop through your records to make sure that you copy only one picture to the output at the time!
Hope this helps,
Jan
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy