Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SQL Command for Converting Hexadecimal values

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-18 : 07:56:53
Sandy writes "Do you know of any SQL Commands that will convert Hexadecimal values to decimal or date formats?

Thanks"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-18 : 08:08:11
Is this?

SELECT CAST(0x11111111 AS INT)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-08-18 : 08:16:26
Hi Sandy, Welcome to SQL Team!

Here's a tortuous solution!

DECLARE @intOutput int,
@strSQL nvarchar(4000),
@strHEX varchar(100)

SELECT @strHEX = 'AB' -- Some hex number to test


IF LEFT(@strHEX, 2) <> '0x' SELECT @strHEX = '0x' + @strHEX
SELECT @strSQL = 'select @intOutput = CAST(' + @strHEX + ' as int)'
EXEC sp_ExecuteSQL @strSQL,
N'@intOutput int OUTPUT',
@intOutput OUTPUT
select @intOutput

Kristen
Go to Top of Page
   

- Advertisement -