日期:2014-05-18  浏览次数:20396 次

SQL2005中不用标识列自动增加编号
ID为:G000000001
增加1位后成G000000002

------解决方案--------------------
SQL code

create table #tt(id varchar(10))
insert into #tt select 'G000000002'
insert into #tt select 'G000000003'
insert into #tt select 'G000000004'
insert into #tt select 'G000000202'
insert into #tt select 'G000000122'

select 'G'
    +replicate('0',len(max(id))-1-len(max(cast(substring(id,patindex('%[1-9]%',id),len(id))as int))+1))
    +cast(max(cast(substring(id,patindex('%[1-9]%',id),len(id))as int))+1 as varchar(10)) from #tt

----------------------------

--G000000203

(1 行受影响)