@@CURSOR_ROWS is the cursor system functions in SQL Server that are used to check the current status or row count. This is useful when we are working with one or more cursors in the procedures. We have to remember that these functions are non-deterministic. So, we have use these functions with extra logic to make right decision for the program flow.
@@CURSOR_ROWS
This function returns the row count or current status of the last opened cursor object. It returns an integer value for the row count or other value as given in the below image.
@@CURSOR_ROWS
Example
1. This example returns -1 for the Cursor_Rows output. Because, the select * statement returns different rows based on the table transaction.
2. This example returns the actual row count value because the row count is static in this query.
Original Script for your experiment:
DECLARE trans CURSOR FOR SELECT TOP 10 [Ac_No],[Transaction_Type] FROM [tblTransaction]; OPEN trans; FETCH NEXT FROM trans; SELECT @@CURSOR_ROWS AS 'Total Rows/Status'; CLOSE trans; DEALLOCATE trans;
