Hi everyone, after doing a lot of digging online I found the following script that allows me to extract all blobs in a column and export them to .tif files on the hard drive. However this particular script saves the files with a filename of a timestamp. I have tried editing this portion of the code but I have not been successful thus far. Would someone be able to help me with saving these files with a filename that includes the value of a corresponding column in the same row of the same table?
_________________________________________________________________________________________________
DECLARE @SQLIMG VARCHAR(MAX),
@IMG_PATH VARBINARY(MAX),
@TIMESTAMP VARCHAR(MAX),
@ObjectToken INT
DECLARE IMGPATH CURSOR FAST_FORWARD FOR
SELECT Column31 from POMS_BACKUP.dbo.DataTable
OPEN IMGPATH
FETCH NEXT FROM IMGPATH INTO @IMG_PATH
WHILE @@FETCH_STATUS = 0
BEGIN
SET @TIMESTAMP = 'c:\IMAGES\' + replace(replace(replace(replace(convert(varchar,getdate(),121),'-',''),':',''),'.',''),' ','') + '.tif'
EXEC sp_OACreate 'ADODB.Stream', @ObjectToken OUTPUT
EXEC sp_OASetProperty @ObjectToken, 'Type', 1
EXEC sp_OAMethod @ObjectToken, 'Open'
EXEC sp_OAMethod @ObjectToken, 'Write', NULL, @IMG_PATH
EXEC sp_OAMethod @ObjectToken, 'SaveToFile', NULL, @TIMESTAMP, 2
EXEC sp_OAMethod @ObjectToken, 'Close'
EXEC sp_OADestroy @ObjectToken
END
CLOSE IMGPATH
_________________________________________________________________________________________________
Again, the above code works to successfully extract the images to tif's, but I need to have them save with the corresponding value of column2 in the same table. Thanks in advance for any help!