把存储过程内容插入到临时表的问题
我有1存储过程up_Bed_Assign,返回的是1个表数据
我现在新建个存储过程up_Bed_AssignBat,在up_Bed_AssignBat新建1个临时表,然后把up_Bed_Assign的查询结果插入到临时表。
一般用下面的方法插入:
INSERT INTO #tmp EXEC up_Bed_Assign ' '
但是因为我在up_Bed_Assign也使用了
INSERT INTO #tmpRoom EXEC sp_executesql @SqlRoom
所以再用INSERT INTO EXEC就会报错,说不能嵌套使用。
大家有什么办法,帮忙!!!
------解决方案--------------------应该考虑使用全局临时表(##开头,需要自己维护建立和删除),好处是 不必多次插入,实现数据交流
INSERT INTO #tmp EXEC up_Bed_Assign ' '
这个方法总给人别扭的感觉
------解决方案--------------------CREATE PROC TEST
AS
SELECT TOP 10* FROM jobs
DROP PROC TEST
select * into #t1
from openrowset( 'msdasql ', 'driver={sql server};server=192.168.111.205;uid=sa;pwd= ', 'exec pubs.dbo.TEST ') AS a
select * from #t1
job_id job_desc min_lvl max_lvl
------ -------------------------------------------------- ------- -------
1 New Hire - Job not specified 10 10
2 Chief Executive Officer 200 250
3 Business Operations Manager 175 225
4 Chief Financial Officier 175 250
5 Publisher 150 250
6 Managing Editor 140 225
7 Marketing Manager 120 200
8 Public Relations Manager 100 175
9 Acquisitions Manager 75 175
10 Productions Manager 75 165
(10 row(s) affected)
------解决方案--------------------1.
Exec sp_serveroption 'servername ', 'Data Access ', 'True '
go
Select * INTO #tmpWho
From OpenQuery(servername, 'Exec 存储过程 ')
2.
先建一个表#TempTable
INSERT INTO [#TempTable] Exec 存储过程