Results 1 to 3 of 3

Thread: Cursor Parameters in MS SQL

  1. #1
    Join Date
    Oct 2002
    Posts
    1

    Cursor Parameters in MS SQL

    Hello Sir,
    I am facing a problem in migrating a cursor declarartion from Oracle to
    MSSQL
    This in Oracle

    cursor cursSku (prId IN NUMBER) is
    select * from sku where p_id = prId;

    Has to be migrated to MSSQL
    Thanks
    Nivedita

  2. #2
    Join Date
    Oct 2002
    Location
    Macon
    Posts
    18
    I don't think that Transact SQL has parameterized CURSORS like PL/SQL. Someone correct me if I'm wrong.

    Here's how to create the cursor(example assuming you're not in a sp):

    --DECLARE @prId variable
    DECLARE @prId int

    --SET @prId TO A VALUE
    SET @prId = 4

    --DECLARE AND DEFINE THE CURSOR
    DECLARE curSku CURSOR FOR
    SELECT *
    FROM sku
    WHERE p_id = @prId


    OPEN curSku --OPEN CURSOR

    /* FETCH ...
    Do your cursor
    processing stuff
    */

    CLOSE curSku --CLOSE CURSOR

    --REMOVE CURSOR REFERENCE
    DEALLOCATE Employee_Cursor

    May want to check out Cursors in Books Online for more help.

    Good Luck!!!

    WiLeYjAcK
    Last edited by wileyjack; 10-25-2002 at 08:29 AM.

  3. #3
    Join Date
    Oct 2002
    Posts
    12
    This is the cursor code I use:

    DECLARE @oldId int
    DECLARE Users_cursor CURSOR FOR SELECT field1, field2
    FROM yourTable

    OPEN Users_cursor
    FETCH NEXT FROM Users_cursor INTO @oldId
    WHILE (@@FETCH_STATUS <> -1)
    BEGIN

    IF (@@FETCH_STATUS <> -2)
    BEGIN
    -----do what you have to do
    END
    FETCH NEXT FROM Users_cursor INTO @oldId
    END
    DEALLOCATE Users_cursor


    Hope this helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •