|
ALL, I have a question ,with respect to executing the stored procedures. can we execute a single stored procedure multiple times like say about a 100 times in a single script If yes... 1) is there a limit that the procedure could be called in the script 2) what is the efficient way to do it. I am thinking of writing another stored procedure which executes this procedure required number of times. I am not sure how to handle this situation. Any advice would be very helpful. Thanks
(comments are locked)
|
|
Try This will execute it 100 times Oleg <!-- Begin Edit Here is the sample to do it with the cursor loop. I will use simple xml to store the procedure parameters, so I don't have to create a temp table: Suppose I want to execute the proc few times each time with different parameters. I can store the parameter values in the xml , open the cursor reading data from it and executing the proc once per cursor loop step: End Edit --> That's the one I would have chosen.
Aug 23 '10 at 10:30 AM
Grant Fritchey ♦♦
Oleg, would it apply, with the same stored procedure, with different parameters exec storedproc (parameter set 1) exec storedproc (parameter set 2) ... 100 times? etc?
Aug 23 '10 at 10:34 AM
Katie 1
@Katie No, it will not. If you need to call it with different parameters then there is no way to do it in the loop (go n is just a shortcut to execute the batch n times). There is a way to do it with the cursor loop if you first create a small temp table and insert the parameters into it as records (one record for all parameters). Then you can create a cursor loop and execute the proc with different set of parameters. I will add a small sample to my answer in few minutes.
Aug 23 '10 at 11:03 AM
Oleg
Thats a great idea Oleg.I will try to implement this idea. Thank you so much.
Aug 23 '10 at 11:18 AM
Katie 1
(comments are locked)
|
|
Hello Here si th example I created...
It is running fine, but it gives an error message "The query has exceeded the maximum number of result sets that can be displayed in the results grid. Only the first 100 result sets are displayed in the grid." But if you are trying to update the data, i dont think you are going to have any problem. Thank you Vpadmala This will work for executing the proc multiple times with same parameters, but then again why write a while loop when go n just does it. With different parameters for each execution, the regular loop cannot unfortunately help though cursor loop can.
Aug 23 '10 at 11:33 AM
Oleg
(comments are locked)
|


Why does the procedure need to be executed a set number of times? Isn't there a method for simply doing the set of operations required?
Grant, this procedure was designed to insert related data into various different(around 10) tables.
I wanted to use this stored procedure to insert around hundred records as part of data import. I was trying to avoid execution 100 times manually executing the proc to insert the data. So was thinking to automate it.