ALTER PROCEDURE [dbo].[TentoSerial]
@num int,
@ret nvarchar(10) output
AS
declare @StringXL nvarchar(50)
declare @CharXL nvarchar(10)
declare @modnum int
set @StringXL='0123456789ABCDEFGHJKLMNPRSTUVWXYZ'
set @CharXL=''
if @num>35936
begin
raiserror('流水号已超过上限35936',16,-1)
return -1
end
if (@num<=32)
begin
set @CharXL=SUBSTRING(@stringxl,@num+1,1)
end
while @num>32
begin
set @modnum=@num%33
set @num=@num/33
set @CharXL=SUBSTRING(@stringxl,@modnum+1,1)+@CharXL
if (@num<=32)
begin
set @CharXL=SUBSTRING(@stringxl,@num+1,1)+@CharXL
end
end
select @ret=right('000'+@CharXL,3)
return 0