How can I export images from MS SQL Server to a file on disk?
- by rball
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