执行一个存存储过程产生数据集后,怎么根据这些数据集创建一个临时表并把数据填充到表里去?
比如 效果要根据这样:select * into #temptable from 物理表名
可以产生一个临时表,但是我要这样实现:
create procedure pname  as select * from 物理表名
exec pname 后产生的数据集如何根据上面一样产生临时表#temptable说明一下,临时表#temptable的列数是不定的,因为存储过程产生的列是动态的,所以不能先建临时表再向里填充来实现!

解决方案 »

  1.   

    修改存储过程代码,在存储过程代码最后将查询结果into 临时表
      

  2.   

    临时表只在当前会话有效吧,在存储过程里面insert之后,执行完存储过程,可能这个表也就没了 ~
      

  3.   

    用实体表也行.
    alter proc 存储过程
    as
    if exists(select 1 from sysobjects where type='U' and name='tbtest')
    drop table tbtest......into tbtest...
      

  4.   

    使用全局临时表
    select * into ##temptable from 物理表名
      

  5.   

    两种方式
    1,先建立与存储过程产生的记录集结构相同的临时表,再用insert select语句
    比如
    create table t1(id int,n varchar(10))
    insert t1 select 1,'a'create proc tst as select * from t1create table #t(id int ,n varchar(10))
    insert #t exec tst2,利用openrowset之类的语句
    use test
    create table t1(id int,n varchar(10))
    insert t1 select 1,'a'create proc tst as select * from t1select * into #t from openrowset('SQLOLEDB','(local)';'sa';'秘码',
       'exec test.dbo.tst') a
    select * from #t
    drop table #t
      

  6.   

    多谢fcuandy(了此残生.) 的第二种方法.
    不过想多问一次,在ORACLE里面有没有openrowset这种方法?或者类似的方法?
    在ORACLE里怎样实现同种的效果呢?
      

  7.   


    2,利用openrowset之类的语句
    use test
    create table t1(id int,n varchar(10))
    insert t1 select 1,'a'create proc tst as select * from t1select * into #t from openrowset('SQLOLEDB','(local)';'sa';'秘码',
    'exec test.dbo.tst') a
    select * from #t
    drop table #t
    再请问一下,如果存储过程tst里存在临时表比如改一下alter proc tst as select * into ##tt from t1  select * from #ttt drop table ##tt,就出现"OLE DB 提供程序 'SQLOLEDB' 指出该对象中没有任何列。"错误,请怎么解决啊
    说明一下:TST里一定有临时表的