You are here:Home » tsql » Export image from image data type data in sql server 2005

Export image from image data type data in sql server 2005

DECLARE @Image VARBINARY(MAX)
SELECT @Image = (select imf from tbl_image )
DECLARE @ObjectToken INT
EXEC sp_OACreate 'ADODB.Stream', @ObjectToken OUTPUT
EXEC sp_OASetProperty @ObjectToken, 'Type', 1
EXEC sp_OAMethod @ObjectToken, 'Open'
EXEC sp_OAMethod @ObjectToken, 'Write', NULL, @Image
EXEC sp_OAMethod @ObjectToken, 'SaveToFile', NULL, 'd:\test.bmp', 2
EXEC sp_OAMethod @ObjectToken, 'Close'
EXEC sp_OADestroy @ObjectToken