Home Forums SQL Server 2008 T-SQL (SS2K8) loop within in a loop of RST now working as expected RE: loop within in a loop of RST now working as expected

  • Hi

    I will try to explain. My starting point is a table with data similar to what I have created in tblDDAccounts. This data is about accounts and when they are due a direct debit

    Account is the account number.

    MonthsBetweenRuns, is the number of month between each direct debit.

    DDCycle is the 1st month in which in the direct debit should take place.

    I am trying to dynamically create a table from this data that will list each account and each month that account is due a direct debit

    Note if an account has a direct debit due each month i.e. MonthsBetweenRuns is = 1 then this account can be excluded.

    All is working the way I would like only its not iterating to account 2 and 3 etc but instead returns the result set for account 1 5 times.

    Thank you so much for any help

    tblDDAccounts

    AccountMonthsBetweenRunsDDCycle

    122

    231

    347

    467

    566

    And my Loop currently returns:

    tblMonths

    accmonth

    12

    14

    16

    18

    110

    112

    12

    14

    16

    18

    110

    112

    12

    14

    16

    18

    110

    112

    12

    14

    16

    18

    110

    112

    12

    14

    16

    18

    110

    112

    What is is suppos to deliver is:

    tblMonths

    accmonth

    12

    14

    16

    18

    110

    112

    21

    24

    27

    210

    37

    311

    33

    47

    41

    56

    512