locked
Loop with Database RRS feed

  • Question

  • User918461375 posted

    Hello........

    I am using Asp.Net C# 4.0 with oracle database. Now i want to execute some codes in loop for the certain values present in database.

    please provide me some links and sample codes.

    Saturday, June 9, 2012 1:25 AM

Answers

  • User79986525 posted

    Hi ,

    You can use cursor or while Loop In database for curcur you can do it like this...

    BEGIN
    
    Declare @sum nvarchar(MAX)
    SET @Sum=0
    Declare ROWSum_Cursor Cursor for select Amount from AmoutTable  WHERE  'condition if any'
    Declare @sum nvarchar(MAX),@Amount nvarchar(MAX),@PredId nvarchar(MAX)
    OPEN InsertSubPrediction_Cursor
            FETCH NEXT FROM ROWSum_Cursor INTO @Amount
             WHILE @@FETCH_STATUS = 0
                    BEGIN
             -- Getting Amount row Wise
                    
                    SET @SUM= convert(decimal(18,2),@Sum) + convert(decimal(18,2),@Amount)
                                            
                    FETCH NEXT FROM ROWSum_Cursor INTO  @Amount
                    END
                    close ROWSum_Cursor
                    deallocate ROWSum_Cursor
                              
                                    END



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, June 9, 2012 1:40 AM