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 - 2002-07-23 : 08:57:30
|
| Mark writes "I have got a problem with looping through recordsets in a stored procedure, it has to be a nested loop (a loop in a loop)I have to update some records that are related to other records in the same tablebut the @@FETCH_STATUS variable can only remember the status of one loop, maybe there is some sort of trick to get the second loop get running independent from the main loop?" |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2002-07-23 : 09:29:15
|
Post your code and someone here will come up with a set based method for you to use(more than likely anyway!!! PeaceRick |
 |
|
|
sterobhun
Starting Member
12 Posts |
Posted - 2002-07-23 : 09:38:37
|
| Assign @@FETCH_STATUS to another variable if you want to keep the result from a previous fetch. |
 |
|
|
skaluva
Starting Member
17 Posts |
Posted - 2002-07-23 : 15:59:24
|
@@FETCH_STATUS reflects the last FETCH executed in the stored procedure, not the FETCH statement executed first the stored procedure. So, you can do as below:Declare Cursor1...Open Cursor1Fetch Next from Cursor1While @@Fetch_Statue = 0 Begin Declare Cursor2... Open Cursor2 Fetch Next from Cursor2 While @@Fetch_Statue = 0 Begin Fetch Next from Cursor2.. End Close Cursor2 Deallocate Cursor2Fetch Next from Cursor1Endhope this helops you..-- Sreequote: Mark writes "I have got a problem with looping through recordsets in a stored procedure, it has to be a nested loop (a loop in a loop)I have to update some records that are related to other records in the same tablebut the @@FETCH_STATUS variable can only remember the status of one loop, maybe there is some sort of trick to get the second loop get running independent from the main loop?"
|
 |
|
|
|
|
|