How can I export images from MS SQL Server to a file on disk?

Posted by rball on Stack Overflow See other posts from Stack Overflow or by rball
Published on 2010-03-09T04:41:52Z Indexed on 2010/03/09 4:51 UTC
Read the original article Hit count: 518

Filed under:
|

I have a User table that has all of their avatars saved in an image field. I'd like to just take that out of the database and store it as a regular file on disk.

I looked around and saw some code for textcopy, but that doesn't seem to be on my machine for some reason. Here is the code I wrote up anyway. Anyone know a way to get this done?

DECLARE @exec_str varchar (255)
SELECT @exec_str =
         'textcopy /S (local)\SQLEXPRESS' +
         --' /U ' + @login +
         --' /P ' + @password +
         ' /D thedatabase' +
         ' /T User'+
         ' /C AvatarImage' +
         ' /F "d:\Avatars\' + User.Name + '.jpg"' +
         ' /O'
FROM [User]
WHERE UserID = 2
EXEC master..xp_cmdshell @exec_str

© Stack Overflow or respective owner

Related posts about sql-server-2008

Related posts about export