Unix Technical Forum

Results of SQL SELECT statement into Stored Procedure

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, ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 07:46 AM
james14@gmail.com
 
Posts: n/a
Default Results of SQL SELECT statement into Stored Procedure

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 07:46 AM
Simon Hayes
 
Posts: n/a
Default Re: Results of SQL SELECT statement into Stored Procedure


<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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 07:47 AM
James
 
Posts: n/a
Default Re: Results of SQL SELECT statement into Stored Procedure

I searched for hours yesterday, and for some reason never came across
that other post of yours - Thanks!

James

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:11 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com