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
 Transact-SQL (2000)
 make SQL read value as hex

Author  Topic 

smithje
Starting Member

32 Posts

Posted - 2006-04-14 : 17:45:38
I need to convert hex data to its real value. Typed directly into the Query Analyzer it works fine [ SELECT CONVERT(INT, 0X0F425B) ]returns 1000027. SQL does require the 0X be added in front.
The problem comes when I try to pass a query result into the formula by concatanation of the 0x and the known hex values. SQL insist on seeing the concatanated value as a text string and gives the error:
Syntax error converting the varchar value '0X0F425B' to a column of data type int.
I have tried converting the data to sql_variant and have changed the concatanation process to use CHAR(48) and CHAR(88) but it still sees it as text and will not convert it. Anybody done this? Know how?
Thanks

nr
SQLTeam MVY

12543 Posts

Posted - 2006-04-14 : 18:37:43
declare @s varchar(20)
select @s = '0F425B'

declare @i int
declare @sql nvarchar(200)
select @sql = 'select @i = 0x' + @s
exec sp_executesql @sql, N'@i int out', @i out
select @i


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

smithje
Starting Member

32 Posts

Posted - 2006-04-14 : 18:44:32
I see it working but it will take some study for me to get this. Thanks.
Go to Top of Page
   

- Advertisement -