March 5, 2012 at 1:24 pm
Hi,
I have a table which stores pictures as an IMAGE datatype and I need to select each one into a seperate file named column_name.jpg. I have 2400+ rows in total. I have been looking at doing this using sp_OACreate and sp_OAMethod but have not been successful. Does anyone have a solution? Thanks!
March 5, 2012 at 3:18 pm
This is tricky at best to do with straight sql. Typically it is much easier to do this with an application. Why do you want to take 2400 images that are tucked away and write them all to a file?
Also, in case you are not aware the image datatype is deprecated. You should instead use varbinary(max), or even better if you can upgrade to 2008 you can use FILESTREAM.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
March 5, 2012 at 3:23 pm
can you add a CLR?
Elliot Whitlow, a contributor here, has a very nice CLR project for file manipulation;
http://nclsqlclrfile.codeplex.com/
the code example like this works great, you cna see how you could parameterize it in a loop, or generate the code for all the files at once:
:
--MSPSaveFileImage
-- Parameters: @FilePath,@FileName,@FileBytes
-- purpose: given an varbinary image column in a table, write that image to disk
-- usage:
declare @myfile varbinary(max)
SELECT @myfile = rawimage FROM myImages WHERE id = 1
EXEC dbo.MSPSaveFileImage 'C:\Data','spinning.gif',@myfile
Lowell
March 5, 2012 at 4:17 pm
I actually need to generate 2400 files. Each named from a value taken from another column in the same table and ending in .jpg
March 5, 2012 at 4:20 pm
Thanks Lowell!! I will give this a try in a loop and see where it takes me.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply