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.
Author |
Topic |
phillikc
Starting Member
6 Posts |
Posted - 2011-08-18 : 09:36:02
|
I'm pretty familiar with SELECT, INSERT and UPDATE, but this situation I believe calls for a loop, which I'm not sure how to write. I have a table of values called ManagedServiceOrgs to supply the OrgID (@OrgID). I would like to loop through each OrgID in this table, supply the OrgID as the variable in the Stored Procedure, and insert the results in a table called #ManageOrgs. Thank you in advance for your help! DECLARE @OrgID char(12)SET @OrgID = '54924'INSERT INTO #ManageOrgs (OrgID) EXEC PTTranProfile.dbo.pt_sp_getorgsfororgs @OrgID |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-18 : 09:40:39
|
you need to use cursor for that.but better way is to rewrite the procedure to accept a list of id values and then use a parsing function to parse them onto a table of values and use it for join with your main table to achieve same result. But for that you need to have rights to modify the procedure.you can find a parsing function belowhttp://visakhm.blogspot.com/2010/02/parsing-delimited-string.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
phillikc
Starting Member
6 Posts |
Posted - 2011-08-18 : 09:44:49
|
Are there any other options? I don't have rights to modify the procedure. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
phillikc
Starting Member
6 Posts |
Posted - 2011-08-18 : 11:07:25
|
Cursor works well. Thank you |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-18 : 11:13:45
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|