--下面是一个表:
declare @table table (id int identity(1,1),window nvarchar(max))
insert into @table (window)
select 'AAAA1111' union all
select 'AAA111' union all
select 'AA11'
select * from @table
/*
id window
----------- ----------
1 AAAA1111
2 AAA111
3 AA11
*/--假设我们要更新表的该字段的后一半变成DD
update @table
set
window.write('DD',len(window)/2,ceiling(cast(len(window) as float)/2))select * from @table
/*
id window
----------- ----------
1 AAAADD
2 AAADD
3 AADD
*/--用write一次就可以更新出现我们要的结果,当然我们也可以用别的办法。
大家常用吗?
insert into @table (window)
select 'AAAA1111' union all
select 'AAA111' union all
select 'AA11'update @table
set window=stuff(window,len(window)/2+1,ceiling(cast(len(window) as int)/2),'DD')
select * from @table