"Varying" in a cursor data type parameter

  • Hi!

    I am not sure if this question has to go here, I wait don't mistake!

    I was doing tests for the 70-461 exam, and I have a doubt about parameters.

    The question says: "What are the two characterisits of a cursor data type parameter?"

    And one answer of them is " It must be used with the VARYING keyword"

    I don't understand when you have to use the "VARYING" keyword and neither what is the meaning of this.

    I tried to look for in google, I found very little explanations and I want to understand this.

    Could someone help me?

    Regards and thanks!:-)

  • Sure, step 1 is Google "CREATE PROC" and that takes you to this page: https://msdn.microsoft.com/en-us/library/ms187926.aspx#Parameters

    Then hit CTRL-F and enter "VARYING" in the search.

    Somewhere shortly below you will see this explanation:

    H. Using an OUTPUT cursor parameter

    The following example uses the OUTPUT cursor parameter to pass a cursor that is local to a procedure back to the calling batch, procedure, or trigger.

    First, create the procedure that declares and then opens a cursor on the Currency table:

    IF OBJECT_ID ( 'dbo.uspCurrencyCursor', 'P' ) IS NOT NULL

    DROP PROCEDURE dbo.uspCurrencyCursor;

    GO

    CREATE PROCEDURE dbo.uspCurrencyCursor

    @CurrencyCursor CURSOR VARYING OUTPUT

    AS

    SET NOCOUNT ON;

    SET @CurrencyCursor = CURSOR

    FORWARD_ONLY STATIC FOR

    SELECT CurrencyCode, Name

    FROM Sales.Currency;

    OPEN @CurrencyCursor;

    GO

    Next, run a batch that declares a local cursor variable, executes the procedure to assign the cursor to the local variable, and then fetches the rows from the cursor.

    DECLARE @MyCursor CURSOR;

    EXEC dbo.uspCurrencyCursor @CurrencyCursor = @MyCursor OUTPUT;

    WHILE (@@FETCH_STATUS = 0)

    BEGIN;

    FETCH NEXT FROM @MyCursor;

    END;

    CLOSE @MyCursor;

    DEALLOCATE @MyCursor;

    GO

    MM



    select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);

  • Forum Etiquette: How to post Reporting Services problems
  • [/url]
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • [/url]
  • How to Post Performance Problems - by Gail Shaw
  • [/url]

  • Thank you for the explanation

    I have understood completely the meaning of VARYING cursor.

    Regards!

  • Viewing 3 posts - 1 through 2 (of 2 total)

    You must be logged in to reply to this topic. Login to reply