• pavel_hant - Wednesday, February 7, 2018 3:39 PM

    Hello,

    I would like to be able to update a varbinary field (named Varbinary_Data of varbinary(max) type) with a value copied from another varbinary field.  I have to do it with a script, and I cannot use a subquery to get the new data in the update statement.

    The data I want to insert in the field looks like 0x504B030400...D04 and it has 43,679 digits (an odd number).

    I am using this update statement:

    update ImageStore
    set Varbinary_Data = CONVERT(varbinary(max), 0x504B030400...D04, 1)
    where Id = 1001

    The result is that in the updated field the data has an extra leading zero after the leading 0x, like: 0x0504B030400...D04, which makes the image unusable.

     Is there a way to do the update avoiding that extra zero to be added?  Thanks, Paul

    You can't save an odd number of digits because VARBINARY only saves whole bytes, which are represented by two nibbles with each nibble being represented by a hex character.  There's no way around it.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)