Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 execute stored procedure multiple times

Author  Topic 

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2013-12-10 : 15:44:28
Hi,

I have a stored procedure which i can't alter that takes several inputs. I need to run it x number of times on a certain table. How can i execute the sp multiple times and each time with different parameters?
I also need to save the output for each idno in a temp table as i need to use that information again.

DECLARE @RC int
DECLARE @IdNo int
DECLARE @StartDate datetime
DECLARE @Plan smallint
DECLARE @UserNo int

-- TODO: Set parameter values here.

EXECUTE @RC = [sp_CreatePackage]
@IdNo
,@StartDate
,@Plan
,@UserNo
GO

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-12-10 : 15:59:07
You would use a WHILE loop or a cursor.

Where will you get the parameter values from?

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2013-12-11 : 01:13:23
Thanks. I will get the parameters from a table.
Go to Top of Page
   

- Advertisement -