Cursor processing First n and then next n records.

  • Hi All,

    I have a stored Procedure which calls 2 other procedures

    Through a cursor.These two nested procedures are for

    inserting and updating a few tables.

    I have to modify it --

    Before running the cursor,I have to ensure that an

    involved table has n or more records .

    If more,I have to process first n and then

    next n records and so on.

    Please help me in thinking about the solution.feel free

    to ask any question.

  • Using IF...ELSE

    The IF statement is used to test for a condition. The resulting flow of control depends on whether the optional ELSE statement is specified:

    • IF specified without ELSE

      When the IF statement evaluates to TRUE, the statement or block of statements following the IF statement are executed. When the IF statement evaluates to FALSE, the statement, or block of statements, following the IF statement is skipped.

    • IF specified with ELSE

      When the IF statement evaluates to TRUE, the statement, or block of statements, following the IF statement, is executed. Then control jumps to the point after the statement, or block of statements, following the ELSE statement. When the IF statement evaluates to FALSE, the statement, or block of statements, following the IF statement is skipped and the statement, or block of statements, following the optional ELSE statement is executed.

    For example, if a stored procedure has been saving any error codes returned by @@ERROR during a transaction, it might have an IF statement similar to the following at the end of the procedure:

    IF (@ErrorSaveVariable <> 0)BEGIN   PRINT 'Errors encountered, rolling back.'   PRINT 'Last error encountered: ' +      CAST(@ErrorSaveVariable AS VARCHAR(10))   ROLLBACKENDELSEBEGIN   PRINT 'No Errors encountered, committing.'   COMMITENDRETURN @ErrorSaveVariable

    See Also

    ELSE (IF...ELSE)

    IF...ELSE

    ©1988-2000 Microsoft Corporation. All Rights Reserved.

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

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