views:

25

answers:

1

I have a SQL Server 2005 table with an image datatype as on of the table fields. I have a specific row I am interested. I'd like to write the binary data in the image field to a file on a network share.

Let's call the share \server\sharename

A: 

This worked for me. Obviously path names and instance names may need to be altered your end.

It requires master..xp_cmdshell enabled (but you could just run bcp directly if there is no need to do it in T-SQL)

EXEC master..xp_cmdshell 
'bcp "SELECT [LargePhoto] FROM [AdventureWorks2008].[Production].[ProductPhoto] WHERE [ProductPhotoID]=70" queryout C:\temp\YourImage.jpg -S(local)\SQL2008 -T -fC:\temp\test.fmt'

It requires the following format file C:\temp\test.fmt

9.0
1
1 SQLBINARY 0 0 "" 1 col1 "" 
Martin Smith
Can you do some formatting to make your answer not have a horizontal scrollbar?
Alex Argo
@Alex - Not without breaking the command line. Why is it causing some problem for you?
Martin Smith