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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-12-22 : 17:10:33
|
| Carla writes "Can you do nested cursors in transact-sql stored procedures?Do the @@FETCH_STATUS values conflict by getting reset for each cursor?Is there a better way to do this?" |
|
|
nathans
Aged Yak Warrior
938 Posts |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2005-12-22 : 19:37:16
|
from SQL Server Books OnLinequote: Returns the status of the last cursor FETCH statement issued against any cursor currently opened by the connection.
while @@fetch_status = 0begin ... while @@fetch_status = 0 begin ... fetch next from inner_cursor into @col1, @col2 end ... fetch next from outter_cursor into @cola, @colbend So for nested cursor like above, the @@fetch_status will always gives you the status of the last fetch-----------------[KH]Learn something new everyday |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-12-22 : 20:00:16
|
| >>Is there a better way to do this?Almost certainly. Sql Server is designed for set-based operations. Using nested cursors is extremely inefficient way to perform selects, inserts, updates, and or deletes. Most likely what you need to do can be done by joining the tables you're cursoring through. You're welcome to post the table structures and your objective for some more ideas.Be One with the OptimizerTG |
 |
|
|
|
|
|