Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tsql 如何循环一个表并为每一行调用一个存储的进程?_Tsql_Stored Procedures - Fatal编程技术网

Tsql 如何循环一个表并为每一行调用一个存储的进程?

Tsql 如何循环一个表并为每一行调用一个存储的进程?,tsql,stored-procedures,Tsql,Stored Procedures,我有一个包含10个值的临时表,如下所示: CREATE TABLE #RequireAuth (val1 int, val2 int /*, etc...*/ ) 我如何调用另一个存储过程,它将接收这10个值并返回6个值 SELECT * FROM #RequireAuth -- Not sure how to call a SP from here? 然后我需要获取这6个值并更新一个不同的表。我对临时表做了一些假设,因为您描述的内容和显示的内容不同,但这是while循环的基本概念 CRE

我有一个包含10个值的临时表,如下所示:

CREATE TABLE #RequireAuth (val1 int, val2 int /*, etc...*/ )
我如何调用另一个存储过程,它将接收这10个值并返回6个值

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

然后我需要获取这6个值并更新一个不同的表。

我对临时表做了一些假设,因为您描述的内容和显示的内容不同,但这是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 val1=@varible
        select @count =count(2) from #RequireAuth where done=0
END

我知道这是被接受的,而且很古老,但这到底与这个问题有什么关系呢?