

DECLARE @t TABLE(id INT,document NVARCHAR(MAX))
INSERT @t VALUES(1,N'谁是天才啊?..AA就是天才啊..');
select charindex(N'AA',document),patindex('%AA%',document)
,substring(document,1,9) from @t
-- substring + patindex
Update @t
set document=case when patindex('%AA%',document)>0
then substring(document,1,patindex('%AA%',document)+1)
else document end
-- stuff + charindex, charindex不能与 text、ntext 和 image 数据类型一起使用
update @t
set document=STUFF(document, CHARINDEX(N'AA',document)+2
, len(document)-CHARINDEX(N'AA',document)-1,null)
-- .write(expression, @Offset, @Length)子句执行对 varchar(max)、nvarchar(max) 和 varbinary(max) 等数据类型的更新
UPDATE @t SET
document.write(null,CHARINDEX(N'AA',document)+1,null);
select * from @t