日期:2014-05-17 浏览次数:20550 次
--建测试表
create table tzs(x varchar(10))
--建存储过程
create proc add_tzs
as
begin
set nocount on
declare @mx varchar(10),@i int,@j1 char(1),@j2 char(1)
select @mx=max(x) from tzs
if @mx is null
begin
insert into tzs(x) values('0000001')
return
end
else
begin
select @i=2,@mx='0'+substring(@mx,patindex('%[^0]%',@mx),8-patindex('%[^0]%',@mx))
select @mx=reverse(@mx)
select @j1=substring(@mx,1,1)
select @j2=case when (@j1>='0' and @j1<='8') or (@j1>='a' and @j1<='y') then char(ascii(@j1)+1)
when @j1='9' then 'a'
when @j1='z' then '0' end
select @mx=stuff(@mx,1,1,@j2)
while(@i<=len(@mx))
begin
if @j1='z'
begin
select @j1=substring(@mx,@i,1)
select @j2=case when (@j1>='0' and @j1<='8') or (@j1>='a' and @j1<='y') then char(ascii(@j1)+1)
when @j1='9' then 'a'
when @j1='z' then '0' end
select @mx=stuff(@mx,@i,1,@j2)
end
select @i=@i+1