0

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

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by sknake
0
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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.