I'm in the process of converting two columns in two separate tables...

One column in Table A has a hexadecimal number (with a nvarchar data type) i.e. "A5000000020" and converting it to a decimal it should be "11338713661472"...

In Table B the column has a decimal number (with a bigint data type) i.e "1434519076864" and converting it to a hexadecimal the would make the value "9D500000005"

I keep getting stuck!!!

How can I successfully convert these columns?!

Thanks in advance!!!

CREATE PROCEDURE Stp_HexToInt
    @HexValue Varchar(20)
AS
BEGIN
    Declare @Query nvarchar(100)
    Declare @Parameters nvarchar(50)
    Declare @ReturnValue Int

    if (charindex('0x',@HexValue) = 0)
        Set @HexValue = '0x' + @HexValue


    Set @Query = N'Select @Result = Convert(int,' + @HexValue + ')'
    Set @Parameters = N'@Result int output'
    Exec master.dbo.Sp_executesql @Query, @Parameters, @ReturnValue Output

    RETURN @ReturnValue
END

Taken from: http://www.codeproject.com/KB/database/ConvertHexToIntUsingSQL.aspx

For going the other way:
http://snippets.dzone.com/posts/show/707

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.