use pubs
SET NOCOUNT ON
go

DECLARE declared_cursor CURSOR LOCAL 
FOR SELECT title_id, price from titles
DECLARE @cursor_var_a CURSOR
DECLARE @cursor_var_b CURSOR
SET @cursor_var_a = declared_cursor
SET @cursor_var_b = @cursor_var_a
OPEN @cursor_var_a      -- opens declared cursor
FETCH @cursor_var_b     -- fetches row 1 from declared_cursor
FETCH declared_cursor   -- fetches row 2
DEALLOCATE declared_cursor
-- keeps cursor open since other references remain,
-- but can't use declared_cursor name to reference the cursor
FETCH @cursor_var_b     -- fetches row 3 
Published in: SQL
Download

Related snippets