Skip to main content

Simple Cursor Example in SQL

    DECLARE @Pram int

    DECLARE aCursor CURSOR
    FOR
        SELECT
            *
           
        FROM
            TableName
           
    OPEN aCursor
   
           
    FETCH NEXT FROM aCursor INTO
        @Pram
       
    WHILE @@FETCH_STATUS = 0
        BEGIN
            --'what you want to do hear'
            FETCH NEXT FROM aCursor INTO
                @Pram
        END
    CLOSE aCursor
    DEALLOCATE aCursor

Comments