declare @a varchar(10) declare @b varchar(10) declare cur cursor for select a,b from a open curfetch next from cur into @a,@b while (@@fetch_STATUS =0) begin if exists (select * from b where a=@a) update b set b=@b from b where a=@a else insert into b select * from a fetch next from cur into @a,@b endclose cur deallocate cur
declare @b varchar(10)
declare cur cursor for
select a,b from a
open curfetch next from cur into @a,@b
while (@@fetch_STATUS =0)
begin
if exists (select * from b where a=@a)
update b set b=@b from b where a=@a
else
insert into b select * from a
fetch next from cur into @a,@b
endclose cur
deallocate cur