Using WRITETEXT to Update image field

  • Hi,

    I need to write a query to update an image field with documents provided. I wrote the following but instead of actually saving the file it is just saving the path and file name in the field.

    How do I actually save the file and not the file name to the image field?

    DECLARE @Pointer_Value varbinary(16)

    SELECT @Pointer_Value = TEXTPTR(ImageField)

    FROM ImageTable

    WHERE ImageTableID = 470093

    WRITETEXT ImageTable.Imagefield @Pointer_Value 'D:\My Documents\TitleAndNameNicholas.doc'

  • First you're going to have to get the file into the database. Your code just specifies a string constant, and you are assuming there is magic to go with it 😉

    I haven't done what you're trying to do, so let's hope one of the heavy hitters will chime in, but in the meanwhile try this.

    Take a look at OPENROWSET in BOL (Books Online, the help function). It lets you query an external file. I use it a lot to import delimited data into the DB as part of stored procedures. You may also have to do a little research into BCP (bulk copy), if it turns out that a BCP format is required.

    Once you have your data where you can treat it like a value in a column, you should be able to reference the column name (not as a constant string, please), and get the results you're after.

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply