Solved

# Conversion of Hex number to decimal format

Posted on 2007-09-28
510 Views
I need to convert a Hexidecimal number (0107017ee440be56) to a decimal format using SQL.  This has to be done during a loop.  Is there any easy way to do this?
0
Question by:blberger

LVL 75

Accepted Solution

SELECT CAST(0x0107017ee440be56 AS BIGINT)  -- prefix a  '0x' and then do a cast
0

LVL 23

Expert Comment

<<SELECT CAST(0x0107017ee440be56 AS BIGINT)  -- prefix a  '0x' and then do a cast>>
Hey that's a cute solution...Thanks...
0

LVL 15

Expert Comment

Racimo: looks like more than one person learned something today. Think you and I can give aneeshattingal some points?
0

LVL 23

Expert Comment

<<Racimo: looks like more than one person learned something today. Think you and I can give aneeshattingal some points?>>
I particularly like the elegance of the solution...(simple and easy)

I'd be glad to give some poinks but I am afraid the only way to do that would be to create a fake question and attribute poinks without rela answer.   I am not sure about what EE's guideline say about that...
0

LVL 23

Expert Comment

In other words..It's good to learn something about SQL once in a blue moon...
0

LVL 75

Expert Comment

>It's good to learn something about SQL once in a blue moon.
as far as I am concerned, from ee, i am learning at least one thing per day, and we are here to help others and learn something new;  I am glad that I helped you guys in this.  :)
0

LVL 23

Expert Comment

<<as far as I am concerned, from ee, i am learning at least one thing per day>>
Lucky you...

<<I am glad that I helped you guys in this>>
I particularly like little tricks and this is one of them...I wish I could pay you back with a few I am aware of...

Anyway that's the kind of thread and spirit that make me like EE...
;)
0

LVL 15

Expert Comment

I went from application developer to database developer almost overnight three months ago and if it weren't for EE, I'd have been on the streets 2-1/2 months ago :-)
0

LVL 75

Expert Comment

As developers we are all missing the requirements:
"This has to be done during a loop."

So here you go:

Declare @Loop integer

Set @Loop = 0
While @Loop < 1000000
Set @Loop = @Loop + 1

-- Now we can apply Aneesh's solution:
SELECT CAST(0x0107017ee440be56 AS BIGINT)
0

LVL 23

Expert Comment

<offtopic moment of delirium>
<<As developers we are all missing the requirements:>>
Common!!! Antony you are spoiling the fun !!!! LOL...!!!
</<offtopic moment of delirium>>
0

LVL 1

Expert Comment

Forced accept.

Computer101
0

## Featured Post

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be \$37.1B.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.