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 |
|
vgr.raju
Yak Posting Veteran
95 Posts |
Posted - 2007-12-07 : 02:33:36
|
| Hello Experts, I have been faced with the same issue regarding whether to use cursor or while loops. Most of the scenarios,I have to fetch the data from table and then execute the stored proc passing the table data as Stored Procedure parameters. I can get it done using cursors as well as while loops. I have looked at the query plans and gathered some other I/O Statistics and I did not see any significant differnces.Overall attitude in the company is to avoid the cursor if possible.I can certainly avoid the cursor but I am not finding any concrete reasons for avoiding the cursors.IF some one can shed light on where the cursors would be more efficient than while loops ,that would be greatly appreciated.Thanks,RajuThanks!Rajuhttp://rajusqlblog.blogspot.com/ |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2007-12-07 : 04:14:55
|
| Are you passing the rows one at a time to the calling procedure? If so, is there any particular reason for this?Cursors are generally slower than set based solutions, there are obviously exceptions to this, and a inefficient query with a while is one of the exceptions.Post your code and you will get more help. |
 |
|
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
|
|
vgr.raju
Yak Posting Veteran
95 Posts |
Posted - 2007-12-11 : 03:57:08
|
| Thank you all.My scenario is not set based and I have to iterate through the data based on values and Cursors make more sense to use.Thanks,RajuThanks!Rajuhttp://rajusqlblog.blogspot.com/ |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-12-11 : 04:08:41
|
Well, if you say you must iterate all records one by one we believe you. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2007-12-11 : 04:21:40
|
quote: Originally posted by Peso Well, if you say you must iterate all records one by one we believe you. E 12°55'05.25"N 56°04'39.16"
You might, I on the other hand have various resevations. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|