![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
hi I have a scenario where I have created a stored procedure wich task is to search in my database with certain criterias. For each record from this search, I want to run a couple of other stored procedure. Here is some code: decare $myid nvarchar(15) select id, desc, customer from project where customer = 'cust1' ------------------------------------------ --HERE IS CODE MISSING-- ------------------------------------------ --for each of the records returned, I want to run 4 stored procedures with the id as parameter. begin execute StoredProcedure1 $myid execute StoredProcedure2 $myid execute StoredProcedure3 $myid execute StoredProcedure4 $myid end The problem is I don't know how to get hold of the result set and loop through. Maybe you can help me. regards Roger |
#3
| |||
| |||
|
|
If performance does matter and you still want to use a cursor, than you might wish to read my recent blog posts on the performance effects of various cursor options. You can find it at http://sqlblog.com/blogs/hugo_kornel...urious-cursor- optimization-options.aspx |
#4
| |||
| |||
|
|
One battle I have to fight in my shop is with colleagues who think that a "poor man's cursor" is better. And maybe sometimes it is. But having a loop where you do SELECT MIN() on a non-indexed temp table with 100000 rows is definitely not. |
#5
| |||
| |||
|
|
Maybe it is, but I doubt it. After investigating the effect of options, I wouldn't be surprised to find a way to beat a cursor with the default options, since they are SLOW - but I have yet to see a "poor man's cursor" that outperforms a _properly optimized_ cursor. |
|
If your colleagues ever show you a way that they think beats a cursor, please share it with me. Might make neat blog fodder. |
|
Hmmm, maybe I'll do a sequel to the cursor episode anyway. The misunderstanding is common enough to warrant some attention on my blog. |
#6
| |||
| |||
|
#7
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |