locked
Looping RRS feed

  • Question

  • I have a table

    acct#  missedpayments  amount

    123             30                           40

    i have to take this account number and loop it throught 30 times and do some calculation and update the amount column .

    how do i do that. 

    Need to take the account number and cycle it based on missedpayemnt and update the amount columns.   Thx

    Thursday, September 22, 2011 9:22 PM

Answers

  • You can use while loop:

    Int @loop=30;

    While @loop <> 0

    Begin

    Select acct#, missedpayments, amount from <TableName>;

    --Perform what ever logic you want for each iteration

    Set @loop=@loop-1;

    if (select @loop=0 ) break;

    else

    continue;

    End

    • Proposed as answer by Peja TaoEditor Monday, September 26, 2011 8:44 AM
    • Marked as answer by Peja TaoEditor Thursday, September 29, 2011 8:29 AM
    Friday, September 23, 2011 6:33 AM