执行一个存存储过程产生数据集后,怎么根据这些数据集创建一个临时表并把数据填充到表里去?
比如 效果要根据这样:select * into #temptable from 物理表名
可以产生一个临时表,但是我要这样实现:
create procedure pname as select * from 物理表名
exec pname 后产生的数据集如何根据上面一样产生临时表#temptable说明一下,临时表#temptable的列数是不定的,因为存储过程产生的列是动态的,所以不能先建临时表再向里填充来实现!
比如 效果要根据这样:select * into #temptable from 物理表名
可以产生一个临时表,但是我要这样实现:
create procedure pname as select * from 物理表名
exec pname 后产生的数据集如何根据上面一样产生临时表#temptable说明一下,临时表#temptable的列数是不定的,因为存储过程产生的列是动态的,所以不能先建临时表再向里填充来实现!
解决方案 »
- 请问这个查询已经如何实现?
- 求一SQL语句
- 我想在一个表中增加一个不能为空的字段,为什么不行呢?
- 搜不出中文的问题,请达人出手
- sql 表的统计问题
- 如何选择时同时给变量赋值? SELECT @count = [count]
- 如何取数据库表的结构信息
- 求解多表查询一例
- sql server 中的sql语句怎样导入到Mysql中(加急)
- ★★★各位大侠,select a , (很复杂子查询) as temp_b , c*temp_b as temp_c from table1(a,b,c为table1的字段)不行,提示因为c*temp_
- not exist与not in的区别
- 请问charindex()函数的用法
alter proc 存储过程
as
if exists(select 1 from sysobjects where type='U' and name='tbtest')
drop table tbtest......into tbtest...
select * into ##temptable from 物理表名
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
不过想多问一次,在ORACLE里面有没有openrowset这种方法?或者类似的方法?
在ORACLE里怎样实现同种的效果呢?
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里一定有临时表的