ALTER function [dbo].[hex](@cardno int )
returns varchar(100)
as
begin
declare @temp_mod int
declare @i int
declare @result varchar(100)
declare @temp_x int
declare @result_values int
declare @j int
declare @tmpresult varchar(100)
set @result=''
set @i=1
set @temp_x=0
set @j=0;
declare @tmpint bigint
set @tmpint=@cardno
if @cardno<0
begin
set @tmpint=~(-@cardno)+1
set @tmpint=@tmpint&0x0FFFFFFFF
end
while @tmpint!=0
begin
set @temp_mod=@tmpint%16
set @tmpint=@tmpint/16
set @result=(case @temp_mod when 10 then 'A'
when 11 then 'B'
when 12 then 'C'
when 13 then 'D'
when 14 then 'E'
when 15 then 'F'
when 16 then 'G'
when 17 then 'H'
when 18 then 'I' else ltrim(str(@temp_mod)) end )+@result
select @j=@j+1
end
if len(@result)>8
begin
select @tmpresult=Right(@result,8)
end
else
begin
select @tmpresult=@result
end
if len(@tmpresult)<8
begin
if len(@tmpresult)=7
select @tmpresult='0'+@tmpresult
else if len(@tmpresult)=6
select @tmpresult='00'+@tmpresult
end
select @result=substring(@tmpresult,7,2)+substring(@tmpresult,5,2)+substring(@tmpresult,3,2)+substring(@tmpresult,1,2)
return cast(@result as varchar)
end
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/40209.html
標籤:MySQL
上一篇:舊人回還能回來嗎?
下一篇:求這個視圖的陳述句怎么寫?
