2013-04-09 72 views
-1

我有10個值這樣一個臨時表:如何遍歷表並調用每行的存儲過程?

CREATE TABLE #RequireAuth (val1 int, val2 int /*, etc...*/) 

我如何可以調用另一個存儲過程,將採取在這10個數值,並返回我回來6個值?

SELECT * FROM #RequireAuth -- Not sure how to call a SP from here? 

然後,我需要採取這6個值,並更新不同的表。

回答

0

我對你的臨時表做了一些假設,因爲你描述的和你展示的是不同的,但是它是基本概念的一個while循環。

CREATE TABLE #RequireAuth (val1 int, done bit default 0) 

declare @varible int 
     ,@count int 


select @count =count(2) from #RequireAuth where done=0 
while (@count>0) 
    BEGIn 
     select top 1 @varible=val1 from #RequireAuth where done=0 
     exec sp_YourProc @variable 

     update R set done=1 from #RequireAuth R where [email protected] 
     select @count =count(2) from #RequireAuth where done=0 
END 
+0

我知道這是被接受和老,但究竟是如何在這個問題上涉及到這個問題? – OGHaza 2014-02-19 21:48:05