5 pts.
 Call Stored Procedure Multiple times
I want to use a SQL script that takes values from one table and then calls a stored procedure multiple times for each of those values. Each time, I am passing in those values as a parameter for each stored procedure call. How can I do that?

Software/Hardware used:
ASKED: May 30, 2008  6:48 PM
UPDATED: August 31, 2010  3:50 PM

Answer Wiki:
You would do this with a cursor (without the syntax error in the original answer ;-) <pre>DECLARE @value INT DECLARE cur CURSOR FOR SELECT value FROM YourTable open cur FETCH NEXT FROM cur INTO @value WHILE @@FETCH_STATUS = 0 BEGIN exec YourProcedure @value exec AnotherProcedure @value FETCH NEXT FROM cur INTO @value END CLOSE cur DEALLOCATE Cur</pre>
Last Wiki Answer Submitted:  August 31, 2010  3:50 pm  by  Denny Cherry   64,520 pts.
All Answer Wiki Contributors:  Denny Cherry   64,520 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.

 64,520 pts.