SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Execute Stored Procedure in a Resultset[:D]
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

RegTyler
Starting Member

11 Posts

Posted - 02/21/2007 :  07:23:16  Show Profile  Reply with Quote

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

Sweden
30265 Posts

Posted - 02/21/2007 :  07:36:55  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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 - 02/22/2007 :  08:45:48  Show Profile  Reply with Quote
Thanks very much!
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30265 Posts

Posted - 02/22/2007 :  09:33:36  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000