Question : Identify when you have reached the last record on a SQL Cursor

Is there anyway to identify when you have reached the last record in a SQL Cursor. I need to manipulate the data within a cusor, but the first and last records need particular data manipulation carried out on them.

Doing this on the first record is relatively straight forward. I am not aware of and EOF property I can check for cursors as you can do in recordsets, does anyone know of a simple way of doing this?

Nathan

Answer : Identify when you have reached the last record on a SQL Cursor

You could try @@CURSOR_ROWS
http://msdn.microsoft.com/en-us/library/ms176044.aspx

Or declare the cursor as STATIC, e.g.

declare c cursor static for ....

And go forward to test
1:
2:
3:
4:
5:
6:
 fetch next from c into @var
 if @@fetch_status = -1
    -- we are on last record
 else
    -- we are not
 fetch prior from c into @var  -- go back to proper location
Random Solutions  
 
programming4us programming4us