O'Reilly logo

Microsoft® SQL Server 2008 R2 Unleashed by Alex T. Silverstein, Chris Gallelli, Paul Bertucci, Ray Rankins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required