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
 Transact-SQL (2000)
 Two cursors and fetchstatus ?

Author  Topic 

Karander
Starting Member

34 Posts

Posted - 2004-09-23 : 08:35:44
Hi!
How to manage two opened cursor. What with the fetchstatus ??
Thanks

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-23 : 08:40:32
first finish one then the other.
maybe you shouldn't use cursor. i'm sure it can be set based. tell us what u want to do, please

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Karander
Starting Member

34 Posts

Posted - 2004-09-23 : 08:49:09
Heh There is really to much to describe ... :(

is it possible to manage two cursor, how to know
when all record in 2. cursor has been fetched and the same with 1. cursor ???

Please tell me, don't say that it is impossible

Thanks
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-23 : 09:05:54
when you finish with the first cursor do:
CLOSE Cursor_name
DEALLOCATE Cursor_name

then use the other cursor.

doing both togehter is tricy and not recommended. but as i never use cursors
i really can't tell if there are any tricks.


Go with the flow & have fun! Else fight the flow
Go to Top of Page

Karander
Starting Member

34 Posts

Posted - 2004-09-23 : 09:32:03
Hey!
I found information that @@fetchstatus returns status to the cursor
with last fetch statement ;) So, it works

"but as i never use cursors" maybe you haven not had problem which could be solved with cursors?

Thanks ;)

P.s. Where can i read about other mssql mechanisms that could replace cursors ?
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2004-09-23 : 09:48:31
quote:
Originally posted by Karander
...
"but as i never use cursors" maybe you haven not had problem which could be solved with cursors?
...


More than likely, he has never come across a problem which couldn't be solved by set-based queries...

Cursors are bad practice in SQL Server...
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-23 : 09:58:45
well u need to start thinking set baset. it helps if you begin with one simple
set and what applies to that set will apply to all others if you group them correctly.
take a look at cursor and try to imagine a set based solution. draw it on a piece of paper.
there are a lot of thigs that can be solved with user-defined functions that people use cursors for.

directly from BOL:

Because @@FETCH_STATUS is global to all cursors on a connection, use
@@FETCH_STATUS carefully. After a FETCH statement is executed, the
test for @@FETCH_STATUS must occur before any other FETCH statement
is executed against another cursor. The value of @@FETCH_STATUS is
undefined before any fetches have occurred on the connection.

For example, a user executes a FETCH statement from one cursor, and
then calls a stored procedure that opens and processes the results
from another cursor. When control is returned from the called stored
procedure, @@FETCH_STATUS reflects the last FETCH executed in the
stored procedure, not the FETCH statement executed before the stored
procedure is called.


if it helps you great.

Go with the flow & have fun! Else fight the flow
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-09-23 : 10:36:45
Just set the first @@FETCH_STATUS to a local variable....

Got a sample somewhere.....



Brett

8-)
Go to Top of Page
   

- Advertisement -