如何在mssql中将十进制转换成十六进制字符串?

如何在mssql中将十进制转换成十六进制字符串?


ALTER function IntToHex(@i int)
returns varchar(20)
as
begin
declare @tmpint int

set @tmpint = @i
declare @result varchar(20)
set @result = ''

while @i <> 0
begin
set @tmpint = @i % 16
set @i = @i / 16

set @result = case @tmpint when 15 then 'F' when 14 then 'E' when 13 then 'D'
when 12 then 'C' when 11 then 'B' when 10 then 'A'
else ltrim(rtrim(str(@tmpint)))
end
+ @result

end


return @result
end