decalre cursor cur_a for select a from table1 where ... open cur_a fetch next from cur_a into @a while @@fetch_status=0 begin .... .... fetch next from cur_a into @a end close cur_a deallocate cur_a
我可能没说清.以baoshan(石头)的例子为例 decalre @a varchar(50),@b varchar(50) decalre cursor cur_a for select a from table1 where ... open cur_a fetch next from cur_a into @a while @@fetch_status=0 begin select @b=select b from table2 where b =@a //我是不想每次打开这个select语句.table比较大,如何方便的处理这步? insert into table3 (b) values (@b) .... fetch next from cur_a into @a end close cur_a deallocate cur_a
select a from table1 where ...
open cur_a
fetch next from cur_a into @a
while @@fetch_status=0
begin
....
....
fetch next from cur_a into @a
end
close cur_a
deallocate cur_a
decalre @a varchar(50),@b varchar(50)
decalre cursor cur_a for
select a from table1 where ...
open cur_a
fetch next from cur_a into @a
while @@fetch_status=0
begin
select @b=select b from table2 where b =@a //我是不想每次打开这个select语句.table比较大,如何方便的处理这步?
insert into table3 (b) values (@b)
....
fetch next from cur_a into @a
end
close cur_a
deallocate cur_a
或者用临时表处理,先取出部分数据集