博学,审问,慎思,明辨,笃行

The World Of wtiancai
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

存储过程替换text,ntext列中的字符串

Posted on 2005-04-28 17:57  wtiancai  阅读(517)  评论(0编辑  收藏  举报
declare @ptr varbinary(16) 
declare @amjnId int 
declare @Position int,@len int 
set @len=datalength('ILOVEHJL')   
declare wux_Cursor scroll Cursor 
for 
select textptr([Name]),[amjnId] from USA201 
for read only 
open wux_Cursor 
fetch next from wux_Cursor into @ptr,@amjnId 
while @@fetch_status=0 
begin 
  select @Position=patindex('%ILOVEHJL%',[Name]) from USA201 where [amjnId]=@amjnId 
  while @Position>0 
  begin 
    set @Position=@Position-1 
    updatetext USA201.[Name] @ptr @Position @len 'i love hjl' 
    select @Position=patindex('%ILOVEHJL%',[Name]) from USA201 where [amjnId]=@amjnId 
  end 
  fetch next from wux_Cursor into @ptr,@amjnId 
end 
close wux_cursor 
deallocate wux_cursor 
go