HELP!!! Converting Hexadecimal to Decimal or vice versa

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2009
Posts: 4
Reputation: KRichardson1127 is an unknown quantity at this point 
Solved Threads: 0
KRichardson1127 KRichardson1127 is offline Offline
Newbie Poster

HELP!!! Converting Hexadecimal to Decimal or vice versa

 
0
  #1
Jul 28th, 2009
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!!!
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,210
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 572
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: HELP!!! Converting Hexadecimal to Decimal or vice versa

 
0
  #2
Jul 28th, 2009
  1. CREATE PROCEDURE Stp_HexToInt
  2. @HexValue VARCHAR(20)
  3. AS
  4. BEGIN
  5. DECLARE @Query nvarchar(100)
  6. DECLARE @Parameters nvarchar(50)
  7. DECLARE @ReturnValue INT
  8.  
  9. if (charindex('0x',@HexValue) = 0)
  10. SET @HexValue = '0x' + @HexValue
  11.  
  12.  
  13. SET @Query = N'Select @Result = Convert(int,' + @HexValue + ')'
  14. SET @Parameters = N'@Result int output'
  15. Exec master.dbo.Sp_executesql @Query, @Parameters, @ReturnValue Output
  16.  
  17. RETURN @ReturnValue
  18. END

Taken from: http://www.codeproject.com/KB/databa...tUsingSQL.aspx

For going the other way:
http://snippets.dzone.com/posts/show/707
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC