表名:table
待更新字段名:hooid
字段hooid里的内容是固定长度的例如:
DAB0000001
DAB0000002
DAB0000003
现在想把hooid字段里面第2位、第3位更改成BA,更新后如下:
DBA0000001
DBA0000002
DBA0000003
麻烦告诉下小弟 谢谢
待更新字段名:hooid
字段hooid里的内容是固定长度的例如:
DAB0000001
DAB0000002
DAB0000003
现在想把hooid字段里面第2位、第3位更改成BA,更新后如下:
DBA0000001
DBA0000002
DBA0000003
麻烦告诉下小弟 谢谢
insert into @table
select 'DAB0000001' union all
select 'DAB0000002' union all
select 'DAB0000003'
update @table
set hooid =stuff(hooid,2,2,'BA')select * from @table
insert into #a
select 'DAB0000001' union all
select 'DAB0000002' union all
select 'DAB0000003'update #a set hooid=replace(hooid,'AB','BA')drop table #a
select * from #a
insert into @table
select 'DAB0000001' union all
select 'DAB0000002' union all
select 'DAB0000003'--方法一
update @table set hooid =stuff(hooid,2,2,'BA')
--方法二
update @table set hooid=left(hooid,1)+'BA'+right(hooid,7)select * from @table