Start position for a reused t- sql cursor?

Posted by Span on Stack Overflow See other posts from Stack Overflow or by Span
Published on 2010-05-26T00:02:13Z Indexed on 2010/05/26 0:11 UTC
Read the original article Hit count: 629

Filed under:
|

I'm working on a stored procedure that uses a cursor on a temporary table (I have read a bit about why cursors are undesirable, but in this situation I believe I still need to use one).

In my procedure I need to step through the rows of the table twice.

Having declared the cursor, already stepped through the temporary table once and closed the cursor, would the position of the cursor remain at the end of the table when re-opened or does it reposition itself to the initial starting position (ie: before the first row)?

Alternatively, to reposition the cursor must I do a 'FETCH FIRST' before stepping through again?

Am I right to assume the 'cost' of doing this repositioning and reusing the cursor would be less than deallocating and reallocating the cursor?

© Stack Overflow or respective owner

Related posts about tsql

Related posts about cursor