日期:2014-05-17  浏览次数:20500 次

流水号生成
数字+字母流水号
0000001
0000002
0000003
0000004
0000005
0000006
0000007
0000008
0000009
000000a
……
000000z
0000010
……
000001z
以此类推
数字+字母流水号 流水号

------解决方案--------------------
为什么还搞字母在里面啊?这到时候匹配或者排序很多麻烦的哦
------解决方案--------------------
把0到9,a到z存入到表格,然后按照顺序拼接。
------解决方案--------------------
数字不用说了
字母可以考虑下用ascii()函数,可以返回一个有序的数值
循环自己设计吧

------解决方案--------------------
赞成DBA_Huangzj
如果实在需要数字+字母,不如试试分成2个字段?
------解决方案--------------------
不建议这样弄啊,过程计算麻烦,检索同样麻烦,给服务器增加额外的计算量,不划算的~!
------解决方案--------------------
引用:
赞成DBA_Huangzj
如果实在需要数字+字母,不如试试分成2个字段?

如果按lz的说法,他这个数据的格式是16进制的,不是单纯的数字。
循环还是lz自己来吧
------解决方案--------------------
函数:incNo(@no)
从@no的右端向左循环判断每一位:
  如果是0-8,则该位增1,返回
  如果是9,则该位改为a,返回
  如果是a-y,则该位增1,返回
  如果是z,则该位改为1,继续循环
------解决方案--------------------

--建测试表
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