(注:其中RemoteServer为定义的一个链接服务器)
declare mycursor2 cursor forward_only static
for select ProductId,ProductName from RemoteServer.northwind.dbo.products
declare @pid1 int,@pid2 int,@pname1 nvarchar(40),@pname2 nvarchar(40)
open mycursor2
fetch next from mycursor2 into @pid2,@pname2
while @@fetch_status=0
begin
update products set productname=@pname2 where productid=@pid2
fetch next from mycursor2 into @pid2,@pname2
end
close mycursor2
deallocate mycursor2
declare mycursor2 cursor forward_only static
for select ProductId,ProductName from RemoteServer.northwind.dbo.products
declare @pid1 int,@pid2 int,@pname1 nvarchar(40),@pname2 nvarchar(40)
open mycursor2
fetch next from mycursor2 into @pid2,@pname2
while @@fetch_status=0
begin
update products set productname=@pname2 where productid=@pid2
fetch next from mycursor2 into @pid2,@pname2
end
close mycursor2
deallocate mycursor2