有个表的ID,一共是10位,它的前三位是用户选择的(如:001,002,003)
它的后7位是系统自动增加1。可是它的类型竟然是字符型!!我现在不能去该数据结构,请问这样的SQL怎么写?
例如:0010123456,0020123456 是存在的数据,那么我在增加的时候,并且设定前三位是“001”,它应该是0123457
它的后7位是系统自动增加1。可是它的类型竟然是字符型!!我现在不能去该数据结构,请问这样的SQL怎么写?
例如:0010123456,0020123456 是存在的数据,那么我在增加的时候,并且设定前三位是“001”,它应该是0123457
select @a = '001'---插入id的sql
insert into a
(id)
select @a + replicate('0',7 - len(sno)) + sno
from
(select max(cast(substring(id,4,7) as integer)) + 1 as sno from a where substring(s,1,3) = @a) b
update table set id= left('000',len('010123456')-len(convert(char,convert(int,'010123456'))))+convert(char,(convert(int,'010123456')+1))
update table set id=left(id,3)+
(convert(char,(convert(int,substring(id,4,6))+1000000)),2,6)
insert into table
(id,...)
values('001' + inttostr(变量+1),...);瞎蒙的
呵呵.........
SubString参考联机帮助!