drop table #t1create table #t1(id char(10)) goinsert into #t1 select '20101000' union all select '20101001' union all select '20101002' union all select '20101003' goselect * from #t1 goupdate #t1 set id = replace(id, '20101', '20111') where id like '20101___' goselect * from #t1
update 表 set 编号='20111' where 编号 like '20101%'
编号 应 like '20101___' 如果用 like '20101%' 可能会出错。 因为 '20120101' 中的 就回被更新为 '20120111'
update 表 set 编号=stuff(编号,1,5,'20111') where 编号 like '20101%'
goinsert into #t1
select '20101000'
union all
select '20101001'
union all
select '20101002'
union all
select '20101003'
goselect * from #t1
goupdate #t1
set id = replace(id, '20101', '20111')
where id like '20101___'
goselect * from #t1
如果用 like '20101%' 可能会出错。 因为 '20120101' 中的 就回被更新为 '20120111'