儲存過程中呼叫另乙個儲存過程的結果集

2021-04-12 20:05:48 字數 789 閱讀 8069

在乙個儲存過程中把另乙個儲存過程當乙個表來使用,在sql server中不支援直接從from後接儲存過程。這個時候我們可以利用臨時表來實現。

舉例:select id, roleid, roletype into #temppurviewtablecontainer  from systempurview  where 1=0

insert #temppurviewtablecontainer exec pmanage_getpurview @type,@id

select * from #temppurviewtablecontainer

需要注意的是,這種方法不能巢狀。例如:

procedure   a  

begin  

...  

insert   #table   exec   b  

end  

procedure   b  

begin  

...  

insert   #table    exec   c  

select   *   from   #table     

end  

procedure   c  

begin  

...  

select   *   from   sometable   

end  

這裡a調b的結果集,而b中也有這樣的應用b調了c的結果集,這是不允許的,會報「insert exec 語句不能巢狀」錯誤。在實際應用中要避免這類應用的發生。

SQL 儲存過程裡呼叫另乙個儲存過程

由於建立了乙個儲存過程,並且要在另乙個儲存過程裡呼叫這個儲存過程所以在網上找了一下相關的 現在總結一下,防止以後還會用到 由於這次我寫的儲存過程只需要返回乙個求和的結果,所以我使用了output 引數,即執行了儲存過程以後返回乙個值 具體 如下 create procedure dbo t1 tes...

SQL用乙個儲存過程呼叫另乙個儲存過程

一 直接呼叫的例子 建被呼叫儲存過程b create procedure b sql nvarchar 500 null,outpara nvarchar 500 output asdeclare sqlstr nvarchar 500 begin set outpara sql end 建呼叫儲存...

在儲存過程中如何使用另乙個儲存過程返回的結果集

在儲存過程中如何使用另乙個儲存過程返回的結果集 2012 10 19 10 44 39 收藏 在儲存過程中如何使用另乙個儲存過程返回的結果集 與這個問題具有相同性質的其他描述還包括 如何在儲存過程中檢索動態sql語句的執行結果?如何實現類似select from exec procedure nam...