@ Cursor_rows
Returns the number of qualified rows in the cursor that is last opened on the connection. To improve performance, Microsoft SQL server can asynchronously populate large key sets with static cursors. You can call @ cursor_rows to retrieve the number of rows that match the cursor when it is called.
| Return Value |
Description |
| -M |
The cursor is asynchronously filled. Return Value (-M) Is the current number of rows in the key set. |
| -1 |
The cursor is dynamic. Because dynamic cursors reflect all changes, the number of rows that match the cursors is constantly changing. Therefore, it is never certain that all rows that meet the condition have been retrieved. |
| 0 |
No opened cursor, no rows that match the last opened cursor, or the last opened cursor has been closed or released. |
| N |
The cursor is fully filled. Return Value (N) Is the total number of rows in the cursor. |
Syntax
@ Cursor_rows
Return type
Integer
Note
If the last opened cursor is asynchronously opened, the value returned by @ cursor_rows is a negative number. IfSp_configure Cursor thresholdIf the value is greater than 0, the keyset driverProgramOr the static cursor is opened asynchronously, and the number of rows in the cursor result set exceeds the cursor threshold.
Example
The following example declares a cursor and uses select to display the value of @ cursor_rows. Before the cursor is opened, set the value to 0. If the value is-1, the cursor key set is asynchronously filled.
Use pubs
Select @ cursor_rows as 'A'
Declare authors_cursor cursor
Select au_lname from authors
Open authors_cursor
Fetch next from authors_cursor
Select @ cursor_rows as 'bb'
Close authors_cursor
Deallocate authors_cursor
----------- 0 (1 row (s) affected) au_lname -------------------------------------- white (1 row (s) affected) ------------1 (1 row (s) affected)