FYI: Convert Hex string data to Int/BigInt

  • Declare

    @i BigInt,

    @Hex VarChar(256),

    @STR nVarChar(4000)

    Select

    @Hex='000000000010', -- String of Hex characters to be converted

    @STR='Set @i=Cast(0x'+@Hex+' as BigInt)'

    Exec sp_ExecuteSQL @STR,N'@i BigInt Output',@i Output

    Print '0x'+@Hex+' = '+Cast(@i as VarChar)

    -- Change BigInt to Int depending on your requirements.



    PeteK
    I have CDO. It's like OCD but all the letters are in alphabetical order... as they should be.

  • Do you have a question?

  • Looks like a nice tip... probably meant to post this under "scripts".

    Thanks, Pete.

    --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)

  • No question, just ran across this issue while researching another topic, thougth I'd drop my 2 cents worth for the forum...

    I'll use Scripts next time.



    PeteK
    I have CDO. It's like OCD but all the letters are in alphabetical order... as they should be.

Viewing 4 posts - 1 through 3 (of 3 total)

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