Using CURSOR Variables in Stored Procedures

Another method available in SQL Server 2008 for passing cursor result sets between stored procedures is using the cursor data type. The cursor data type can be used to bind a cursor result set to a local variable, and that variable can then be used to manage and access the cursor result set. Cursor variables can be referenced in any of the cursor management statements: OPEN, FETCH, CLOSE, and DEALLOCATE.

A stored procedure can pass cursor variables as output parameters only; cursor variables cannot be passed as input parameters. When defining a CURSOR output parameter, you must also specify the VARYING keyword.

When assigning a cursor to a cursor variable, you must use the SET command because an assignment ...

Get Microsoft® SQL Server 2008 R2 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.