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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 does this work exec sp (select id from tbl)
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mike13
Posting Yak Master

Netherlands
211 Posts

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

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

chadmat
The Chadinator

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

-Chad
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 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)

http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm
This will make sure you just call sp once rather than inside a cursor or a loop

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
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.03 seconds. Powered By: Snitz Forums 2000