This is a discussion on Results of SQL SELECT statement into Stored Procedure within the SQL Server forums, part of the Microsoft SQL Server category; --> I need to run a stored procedure on all the results of a select query. For a simplified example, ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I need to run a stored procedure on all the results of a select query. For a simplified example, I'd like to be able to do something like this: SELECT JobID, QtyToAdd FROM Jobs WHERE QtyToAdd > 0 Then for the results of the above: EXEC sp_stockadd @JobID, @QtyToAdd Where the above line ran for every result from the above select query. Anyone able to shed some light on how to do this? Many thanks, James |
| |||
| <james14@gmail.com> wrote in message news:1111512004.569203.32960@g14g2000cwa.googlegro ups.com... >I need to run a stored procedure on all the results of a select query. > > For a simplified example, I'd like to be able to do something like > this: > > SELECT JobID, QtyToAdd > FROM Jobs > WHERE QtyToAdd > 0 > > Then for the results of the above: > > EXEC sp_stockadd @JobID, @QtyToAdd > > Where the above line ran for every result from the above select query. > > Anyone able to shed some light on how to do this? > > Many thanks, > James > Rewriting your proc to work on a set of data, not on a single JobID would probably be the best option, otherwise see this thread: http://groups-beta.google.com/group/...fc0760e026886e By the way, don't use the sp_ prefix for stored procs - it's reserved for system procs, and MSSQL will try to find it in the master database before looking in a user one. Simon |