首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

SQL2005中不用标识列自动增加编号,该如何解决

2012-05-08 
SQL2005中不用标识列自动增加编号ID为:G000000001增加1位后成G000000002[解决办法]SQL codecreate table #

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 行受影响) 

热点排行
Bad Request.