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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 nested cursors in transact-sql stored procedure

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

Posted - 2005-12-22 : 17:31:35
Please post in more detail.

Read for guidelines:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Nathan Skerl
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2005-12-22 : 19:37:16
from SQL Server Books OnLine
quote:
Returns the status of the last cursor FETCH statement issued against any cursor currently opened by the connection.

while @@fetch_status = 0
begin
...
while @@fetch_status = 0
begin
...
fetch next from inner_cursor into @col1, @col2
end
...
fetch next from outter_cursor into @cola, @colb
end

So for nested cursor like above, the @@fetch_status will always gives you the status of the last fetch

-----------------
[KH]

Learn something new everyday
Go to Top of Page

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 Optimizer
TG
Go to Top of Page
   

- Advertisement -