日期:2014-05-17 浏览次数:20718 次
create function dbo.Convert10to16
(@x int) returns varchar(1000)
as
begin
DECLARE @Return varchar(1000),@ind int,@byte binary(1),@byte1 int,@byte2 int,@bin varbinary(1000)
SELECT @bin=cast(@x as varbinary(4))
SELECT @Return='',@ind = 1
WHILE ( @ind <= datalength(@bin) )
BEGIN
SELECT @byte = substring(@bin, @ind, 1);
SET @byte1 = @byte / 16
IF(@byte1 >= 10)
SELECT @Return = @Return +
CASE @byte1
WHEN 10 THEN 'A'
WHEN 11 THEN 'B'
WHEN 12 THEN 'C'
WHEN 13 THEN 'D'
WHEN 14 THEN 'E'
WHEN 15 THEN 'F'
END
ELSE
SELECT @Return = @Return + convert(char(1),@byte1)
SET @byte2 = @byte % 16
IF(@byte2 >= 10)
SELECT @Return = @Return +
CASE @byte2
WHEN 10 THEN 'A'
WHEN 11 THEN 'B'
WHEN 12 THEN 'C'
WHEN 13 THEN 'D'
WHEN 14 THEN 'E'
WHEN 15 THEN 'F'
END
ELSE
SELECT @Return = @Return + convert(char(1),@byte2)
SELECT @ind = @ind + 1;
END
return @Return
end