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
 General SQL Server Forums
 Script Library
 Execute Stored Procedure in a Resultset[:D]

Author  Topic 

RegTyler
Starting Member

11 Posts

Posted - 2007-02-21 : 07:23:16

I have a sql server resultset that returns productid numbers. I would like to loop thru this resultset and run a stored procedure using the productid as the input parameter. Any samples would be helpful. thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-21 : 07:36:55
create table #stage (ProductID INT)

INSERT #Stage
EXEC uspMySP

DECLARE @MinPID INT, @MaxPID INT
SELECT @MinPID = MIN(ProductID), @MaxPID = MAX(ProductID)
FROM #Stage

WHILE @MinPID <= @MaxPID
BEGIN
EXEC MyOtherSP @MinPID

SELECT @MinPID = MIN(ProductID)
FROM #Stage
WHERE ProductID > @MinPID
END


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

RegTyler
Starting Member

11 Posts

Posted - 2007-02-22 : 08:45:48
Thanks very much!
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-22 : 09:33:36
Hereafter avoid posting in this forum. This forum is for working scripts only.
There are other forums more suitable for these kind of questions.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -