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)
 Convert Negative Decimal to Hexadecimal

Author  Topic 

mp
Starting Member

2 Posts

Posted - 2008-06-12 : 12:06:58
This function allows me to convert decimal smallint into hexadecimal.
but this function doesn't convert negative decimal numbers into hexadecimal.

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO



ALTER function DECTOHEX(@n int )
--Converts a decimal number to hexadecimal.
returns varchar(255)
as
BEGIN
DECLARE @i int,@temp int, @s varchar(255)
SET @i=@n
SET @s=''
WHILE (@i>0)
BEGIN
SET @temp=@i % 16
SET @i=@i /16
IF @temp>9
SET @s=char(55+@temp)+@s
ELSE
SET @s=char(48+@temp)+@s
END
RETURN @s
END

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-06-12 : 12:31:20
Select cast(your_value as varbinary(100))

Madhivanan

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

mp
Starting Member

2 Posts

Posted - 2008-06-12 : 13:02:35
simple enough...
thanks so much.
Go to Top of Page
   

- Advertisement -