游标:create proc a
@1 cursor varying out,
@2 cursor varying out
as
declare b cursor local for select * from table1
declare c cursor local for select * from table1
open b
open c
set @1=b
set @2=c
godeclare @a cursor,@b cursorexec a @a out,@b out
fetch @a
fetch @b
fetch @b
fetch @b
fetch @aclose @a
close @bdeallocate @a
deallocate @bdrop proc a

解决方案 »

  1.   

    --例子:
    create proc p_test
    as
    select name from sysobjects
    as--调用它上面存储过程的结果集
    create table #t(name sysname)  --创建临时表,保存存储过程的调用结果
    insert into #t exec p_test
    select * from test
      

  2.   

    --调用它上面存储过程的结果集
    create table #t(name sysname)  --创建临时表,保存存储过程的调用结果
    insert into #t exec p_test
    select * from #t
      

  3.   

    存储过程能够返回表,然后利用 “insert ... exec”你可以将结果保存到一个临时表中。不过,更好的办法是使用返回表的UDF。
      

  4.   

    使用UDF,具有“视图”的作用,又有存储过程的灵活性。例如:
    select * from p_test(@id,getdate()) where age>80