SQL Using sp_describe_cursor

Using sp_describe_cursor

use pubs
SET NOCOUNT ON
go


DECLARE authors_cursor CURSOR KEYSET FOR
SELECT au_lname
FROM authors
WHERE au_lname LIKE 'S%'

OPEN authors_cursor

-- Declare a cursor variable to hold the cursor output variable
-- from sp_describe_cursor
DECLARE @Report CURSOR
-- Execute sp_describe_cursor into the cursor variable

EXEC master.dbo.sp_describe_cursor 
    @cursor_return = @Report OUTPUT, 
    @cursor_source = 'global', 
    @cursor_identity = 'authors_cursor'
-- Verify that the cursor variable contains information
IF cursor_status('variable', '@Report') != 1
     print 'No information available from the cursor'
ELSE BEGIN   
-- Fetch all the rows from the sp_describe_cursor output cursor
    WHILE (@@fetch_status = 0)
    BEGIN
        FETCH NEXT from @Report
    END
END
-- Close and deallocate the cursor from sp_describe_cursor
IF cursor_status('variable','@Report') >= -1 
BEGIN
    CLOSE @Report
    DEALLOCATE @Report
END
GO
-- Close and deallocate the original cursor
CLOSE authors_cursor
DEALLOCATE authors_cursor
GO