March 19, 2009 at 1:28 pm
I have a stored procured that reads a text file which contains hexadecimal numbers.
I need to convert these to decimals. The format is like this:
49B21B89 004E4E1B 00006F1F 05F2DEB9
49B9F0CD 004CB3B9 00011F2D 05F3C9E3
I can use a scientific calculator to do the conversion but need to calculate it within the stored procedure.
Any suggestions?
Thanks, Grady Christie
March 19, 2009 at 1:36 pm
Try something like this:
declare @Bin varbinary(100);
select @Bin = 0x004E4E1B;
select cast(@Bin as int);
Does that help?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
March 20, 2009 at 4:13 pm
That works perfectly!
Many Thanks, Grady Christie
March 20, 2009 at 5:41 pm
So, how did you manage to prepend the '0x' to the character data to get it to work correctly?
--Jeff Moden
Change is inevitable... Change for the better is not.
March 23, 2009 at 7:07 am
Jeff Moden (3/20/2009)
So, how did you manage to prepend the '0x' to the character data to get it to work correctly?
Not sure how Grady did it. I would just use Replace on the spaces in the string. Replace them with space-zero-x, and then add one to the beginning. That's the easy part of this.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
March 23, 2009 at 2:12 pm
Grady Christie (3/20/2009)
That works perfectly!Many Thanks, Grady Christie
Grady,
How did you manage to prepend the "0x" to your columns to get this to work correctly?
--Jeff Moden
Change is inevitable... Change for the better is not.
March 24, 2009 at 7:32 pm
C'mon Grady... the reason why I'm asking is because I believe you're getting the wrong answer. Besides, it's a two way street here. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply