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

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 does this work exec sp (select id from tbl)

Author  Topic 

mike13
Posting Yak Master

219 Posts

Posted - 2013-05-04 : 04:11:49
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

1974 Posts

Posted - 2013-05-04 : 14:16:37
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

52326 Posts

Posted - 2013-05-06 : 02:38:34
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
   

- Advertisement -