• guerillaunit (10/28/2012)


    Hello, I am using the following code to try to convert my hexadecimal string to binary format:

    DECLARE @MYHEX AS VARCHAR(MAX)

    SET @MYHEX = '0000C180880810010000'

    SELECT CONVERT(VARBINARY(MAX), @MYHEX, 1)

    I get this error when I run it:

    Error converting data type varchar to varbinary.

    What am I doing wrong?

    Books online states that if using style 1, which you have specified, that the string must include 0x like so

    DECLARE @MYHEX AS VARCHAR(MAX)

    SET @MYHEX = '0x0000C180880810010000'

    SELECT CONVERT(VARBINARY(MAX), @MYHEX, 1)

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉