日期:2014-05-17 浏览次数:20682 次
create function inttohex(@i bigint)
returns varchar(15)
begin
declare @r varchar(15)
set @r=''
while @i/16>0
begin
set @r=
(case
when (@i % 16)<=9 then convert(varchar(1),@i % 16)
when (@i % 16)=10 then 'A'
when (@i % 16)=11 then 'B'
when (@i % 16)=12 then 'C'
when (@i % 16)=13 then 'D'
when (@i % 16)=14 then 'E'
when (@i % 16)=15 then 'F'
end) +@r
set @i=@i/16
end
if @i>0
set @r=(case
when (@i % 16)<=9 then convert(varchar(1),@i % 16)
when (@i % 16)=10 then 'A'
when (@i % 16)=11 then 'B'
when (@i % 16)=12 then 'C'
when (@i % 16)=13 then 'D'
when (@i % 16)=14 then 'E'
when (@i % 16)=15 then 'F'
end)+ @r
return @r
end
go
DECLARE @a BIGINT=123456789
SELECT stuff(master.dbo.fn_varbintohexstr(cast(@a as varbinary(6))),1,2,'')