游标操作

--
测试表--

create table xinwen(
id
int identity primary key ,
nr
nvarchar ( 500 )
)
-- 测试数据--
insert into xinwen values ( ' tupian/1.jpg ' )
insert into xinwen values ( ' tupian/2.jpg ' );
insert into xinwen values ( ' tupian/3.jpg ' );

GO
-- 利用游标和Replace函数实现你的需求--
declare aa cursor for
select id,nr
from xinwen
open aa
declare @content nvarchar ( 500 ), @id int , @newContent nvarchar ( 500 )
fetch next from aa into @id , @content
while ( @@fetch_status = 0 )
begin
set @newContent = REPLACE ( @content , ' tupian/ ' , ' http://www.xxxxx.com/tupian/ ' )
update xinwen set nr = @newContent where id = @id
fetch next from aa into @id , @content
end
close aa
deallocate aa
GO

你可能感兴趣的:(c#代码,insert,测试,table)