on 2011 Feb 23 1:54 PM
The title says it all. HEXTOINT can only convert integers up to 32 bit. I need to convert a 48 bit-long number from hex to decimal and viceversa.
BEGIN DECLARE @hex VARCHAR ( 100 ); DECLARE @bigint BIGINT; SET @hex = '7048860DDF79'; EXECUTE IMMEDIATE STRING ( 'SET @bigint = CAST ( 0x', @hex, ' AS BIGINT )' ); SELECT @bigint; END; @bigint 123456789012345
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Another option, inspired by Breck's solution:
create or replace function hextobigint( @in varchar(16) )
returns unsigned bigint
begin
declare @result unsigned bigint;
set @result = (select cast(v1 as unsigned bigint)
from openstring(value '0x' || @in) with (v1 binary(8))
option(hexadecimal on) as x);
return @result;
end
go
select hextobigint( '7048860DDF79')
go
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
11 | |
10 | |
10 | |
10 | |
8 | |
7 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.