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 |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2010-02-05 : 10:43:49
|
| I am using two cursors (cursor1, cursor2). Cursor2 is within cursor1 in my sql operations.While within cursor2, how can I exit cursor2 and continue with cursor1?Thank you |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-05 : 10:46:58
|
| can i ask for what purpose you need two cursors? |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-02-05 : 11:04:28
|
the direct answer to your question is answered by this:WHILE 1 = 1 BEGIN PRINT 'foo' BREAKEND However, if you tell us what you are doing with your nested cursors then we'll likely be able to show you a much better way of doing things.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2010-02-05 : 11:05:10
|
| The existing stored procedure loops through a set of records by cursor1 to get several values of a field, then these values are used in the second cursor.This is an existing stored procedure which the business is using...Thanks |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-02-05 : 11:07:21
|
| Assuming cursor2 is the inner cursor, don't do the FETCH on Cursor2 and let it continue to Cursor1's FETCH. |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-02-05 : 11:09:43
|
| you may also want to close and deallocate cursor2 if its build using the variables et for cursor 1.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-02-05 : 11:37:51
|
quote: Originally posted by Transact Charlie you may also want to close and deallocate cursor2 if its build using the variables et for cursor 1.
Yes, absolutly. I'd say it is a MUST to deallocate the inner cursor if it is declared inside the outer one. |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2010-02-05 : 14:28:16
|
| so doiing a break within cursor 2 means that it jumps out of cursor2 and continues with cursor1 ? |
 |
|
|
|
|
|
|
|