在存處過程中要用到另一個存處過程的結果,怎麼辦 create table #临时表(结构和返回结构相同 int)insert #临时表 exec 过程名select * from #临时表 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://expert.csdn.net/Expert/topic/2142/2142802.xml?temp=.5115167 http://expert.csdn.net/Expert/TopicView1.asp?id=2142802 参考:create table #table(id int identity,txt varchar(1000))insert into #table(txt) exec master..xp_cmdshell 'dir c:\*.'select * from #table用存储过程插入数据在INSERT 语句中可以通过执行存储过程来取得要插入的数据所插入的数据是存储过程中SELECT 语句所检索的结果集使用存储过程插入数据的语法如下INSERT [INTO]{ table_name WITH ( <table_hint_limited> [...n])| view_name| rowset_function_limited }{ [(column_list)]EXECUTE procedure其中procedure 既可以是一个已经存在的系统存储过程或用户自定义的存储过程也可以在INSERT 语句中直接编写存储过程例11-4 对每个部门求员工工资总额并把结果存入department_info 表中use panguinsert into department_info(dept_id, d_wage)execute ('select dept_id, sum(e_wage)from employeegroup by dept_id')select * from department_info运行结果如下(7 row(s) affected)dept_id d_chief_name d_location e_num d_wage------- -------------------- -------------------------------------------------- ------ ------------1001 dbo NULL NULL 15000.00001002 dbo NULL NULL 19500.0000 create table #temp(结构和返回结构相同 int)insert #temp exec yourprocnameselect * from #temp create table # (col1.........)insert into # exec proc_nameselect * from #drop table # 返回數據集列是動態的能不能不create #來操作??就像select *into #aaafrom tablea一樣我試了不行不知大家有甚麼好辦法 你可以考虑使用table变量,声明变量的方法是声明普通变量和建立表的结合。详悉方法请查看帮助文件。 用全局临时表:create proc 过程名asselect * into ##全局临时表 from 表go----exec 过程名select * from ##全局临时表 sql server2005的安装问题 怎样知道一个table有没有在用index? ~~~~~~~创建如下的存储过程或者是查询(视图)~~~~~~~~高手 come on 如何恢復數據庫 问一个查询实现,不能用 cube ,要求立刻马上。。 入门 SQL server2005如何恢复数据库? 递归的新问题,最后一步怎样去 掉重复记录 一个SQL语句,急! 请问,为什么我改变数据库后无法保存? 日期型字段相减的问题 如何取得网上邻居的一些机器的名称?
insert into #table(txt) exec master..xp_cmdshell 'dir c:\*.'
select * from #table用存储过程插入数据
在INSERT 语句中可以通过执行存储过程来取得要插入的数据所插入的数据是存储
过程中SELECT 语句所检索的结果集使用存储过程插入数据的语法如下
INSERT [INTO]
{ table_name WITH ( <table_hint_limited> [...n])
| view_name
| rowset_function_limited }
{ [(column_list)]
EXECUTE procedure
其中procedure 既可以是一个已经存在的系统存储过程或用户自定义的存储过程也
可以在INSERT 语句中直接编写存储过程
例11-4 对每个部门求员工工资总额并把结果存入department_info 表中
use pangu
insert into department_info(dept_id, d_wage)
execute ('select dept_id, sum(e_wage)
from employee
group by dept_id')
select * from department_info
运行结果如下
(7 row(s) affected)
dept_id d_chief_name d_location e_num d_wage
------- -------------------- -------------------------------------------------- ------ ------------
1001 dbo NULL NULL 15000.0000
1002 dbo NULL NULL 19500.0000
insert #temp exec yourprocname
select * from #temp
select *
into #aaa
from tablea一樣我試了不行不知大家有甚麼好辦法
as
select * into ##全局临时表 from 表
go----
exec 过程名
select * from ##全局临时表