select @s_str='http://www.fcyz.cn/' --要替换的字符串
,@d_str='/sitemanager/20140616094357/' --替换成的字符串
declare @ID nvarchar(50)
DECLARE CURSORID CURSOR for SELECT ID FROM CMS_Content
OPEN CURSORID
FETCH NEXT FROM CURSORID into @ID
WHILE @@FETCH_STATUS=0
BEGIN
--开始替换
declare @p varbinary(16),@postion int,@rplen int
select @p=textptr(Contents),@rplen=len(@s_str),@postion=charindex(@s_str,Contents)-1 from CMS_Content where ID =@ID
print @postion
while @postion>0
begin
updatetext CMS_Content.Contents @p @postion @rplen @d_str
select @postion=charindex(@s_str,Contents)-1 from CMS_Content where ID =@ID
end
--结束替换
FETCH NEXT FROM CURSORID into @ID
END
CLOSE CURSORID
DEALLOCATE CURSORID