Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert hexadecimal value into bigint

I am getting some trouble converting a string (representing a hexadecimal number) into a bigint. I would also like this to happen inside a function and as effiecient as possible. Is there anyway of exploiting the built-in functions? Here is an example of what I want to do:

select convert (bigint, '0000010d1858798c')
like image 948
Corovei Andrei Avatar asked Jul 27 '11 11:07

Corovei Andrei


1 Answers

The SQL Server 2008 release updated the CONVERT() function to be able to convert hexadecimal values:

select convert(bigint, convert (varbinary(8), '0x0000010d1858798c', 1))

Result:

1155754654092 (decimal) ( ==  0x0000010d1858798c )
like image 97
Mitch Wheat Avatar answered Sep 30 '22 11:09

Mitch Wheat