SQL Shack · January 23, 2020
An overview of the SQL cursor @@FETCH_STATUS function
This article introduces SQL Server cursors and examines the @@FETCH_STATUS system function used to control row-by-row processing. It explains cursor declaration, opening, fetching, closing and deallocation before examining the status returned by individual fetch operations.
Examples distinguish successful fetches, failed fetches and missing rows. The discussion illustrates why checking the status of the appropriate fetch is important when controlling loops, particularly where multiple cursors are involved.