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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 does this work exec sp (select id from tbl)
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

219 Posts

Posted - 05/04/2013 :  04:11:49  Show Profile  Click to see mike13's MSN Messenger address  Reply with Quote

I want to run the store procedure for all the records that are returned form the select

EXEC SP_BACK_Order_checkandmove (SELECT ORDERID FROM T_Order_Main WHERE (Orderstatus = 7))

Do not think this is the correct way to do this.
How should i do it?

Thanks a lot

The Chadinator

1974 Posts

Posted - 05/04/2013 :  14:16:37  Show Profile  Visit chadmat's Homepage  Reply with Quote
You need to create a cursor and execute the SP for each row.

Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 05/06/2013 :  02:38:34  Show Profile  Reply with Quote
much better approach if its possible would be to rewrite sp to accept a list of values and then process it (there are multiple ways of doing this. refer below link)
This will make sure you just call sp once rather than inside a cursor or a loop

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next 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.04 seconds. Powered By: Snitz Forums 2000