如果你碰到过text类型不能replace ,相信一定很痛苦。于是我在CSDN狠狠
的搜了一把。也许是Sql Sever水平太差吧 ,按照邹建大哥提供的方法老是搞
不定替换,于是写了这个程序,贡丑了! 以下根据邹建大哥改写的存储过程:CREATE PROCEDURE replace_String
@s_str varchar(8000),
@d_str varchar(8000)
 AS--因为只能用patindex,所以对于搜索字符串做处理
set @s_str='%'+@s_str+'%'--定义游标,循环处理数据
declare @id int
declare #tb cursor for select id from table1
open #tb
fetch next from #tb into @id
while @@fetch_status=0
begin
--字符串替换处理
declare @p varbinary(16)
,@p1 int,@p2 int
,@rplen int,@step int,@len int select @p=textptr(content)
,@rplen=len(@s_str)-2
,@step=len(@d_str)
,@p1=patindex(@s_str,content)
,@len=datalength(content)
,@p2=0
from table1 where id=@id

while @p1>0
begin
set @p2=@p1+@p2-1
updatetext table1.content @p @p2 @rplen @d_str
select @p2=@p2+1,@p1=patindex(@s_str,substring(content,@p2+1,@len))
from table1 where id=@id
end
fetch next from #tb into @id
end
close #tb
deallocate #tb--显示结果
select datalength(content),* from table1
GO