日期:2014-05-17  浏览次数:20951 次

同一字段所有数据更新的问题
比如我的数据库里有个字段叫URL

有三条URL数据

www.aaa.com/?1
www.aaa.com/?2
www.aaa.com/?3


我现在想把字段三条数据更新为
www.bbb.com/?1
www.bbb.com/?2
www.bbb.com/?3

也就是说只刷新“?”前面的字段

------解决方案--------------------
replace替换不就可以了吗

------解决方案--------------------
declare @s_str varchar(8000),@d_str varchar(8000)
select @s_str= 'www.aaa.com ' --要替换的字符串
,@d_str= 'www.bbb.com ' --替换成的字符串
declare @id int
declare #rpc cursor for select AnnounceID from dv_bbs1
open #rpc
fetch next from #rpc into @id
while @@fetch_status=0
begin
declare @p varbinary(16),@postion int,@rplen int
select @p=textptr(body)
,@rplen=len(@s_str)
,@postion=charindex(@s_str,body)-1
from dv_bbs1 where AnnounceID=@id
while @postion> 0
begin
updatetext dv_bbs1.body @p @postion @rplen @d_str
select @postion=charindex(@s_str,body)-1 from dv_bbs1 where AnnounceID=@id end
fetch next from #rpc into @id
end
close #rpc
deallocate #rpc