Home Forums SQL Server 2008 T-SQL (SS2K8) Help required to extra image from varbinary column and create image on file system RE: Help required to extra image from varbinary column and create image on file system

  • Charlottecb (9/21/2011)


    SQLServer 2008.

    Problem: I have a table populated by an external system which stores image data in a varbinary column. I need to create a trigger on the table so that on an insert to the table, the trigger fires and picks up the newly inserted record and extracts the varbinary data and outputs it to a physical image file with a name composed of the recordID + '.JPG' (or whatever graphic format is used) on the hard disk then I can write a row to another table with the filename. I don't mind if the generated file is a JPG or GIF or PNG although I would prefer it not to be a BMP due to the size of these.

    Creating the trigger is no problem - the issue I am having is extracting the data from varbinary column and creating the graphic file.

    I've tried googling for this and I can't find a complete solution anywhere. Ideally this needs to run on the SQLServer within a trigger so that it is fully automated.

    Can anyone help me with this?

    Many thanks

    Charlotte CB

    Do you know which format it is being sent in as? Regardless, SSIS is the tool to use. You should be able to create an SSIS package to pull your data and create you image file. Then your trigger just needs to call the package. This seems like an extremely strange requirement. You put an image in the database and then immediately write it disc. Can you just skip over putting the image in the database in the first place?

    _______________________________________________________________

    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/