• ashishkumarrai (9/14/2016)


    J Livingston SQL (9/13/2016)


    ashishkumarrai (9/13/2016)


    It seems this is not what I am after. I want the filler data to feed to bucket in recursive way and store each recursion. the output should look like:

    After 1st iteration

    BucketID | FullCapacity | CurrentAmount

    ---+--------------+--------------

    1 | 85 | 85

    2 | 80 | 5

    3 | 75 | 0

    4 | 70 | 0

    5 | 50 | 0

    6 | 40 | 0

    ---+--------------+--------------

    After second iteration

    BucketID | FullCapacity | CurrentAmount

    ---+--------------+--------------

    1 | 85 | 0

    2 | 80 | 45

    3 | 75 | 0

    4 | 70 | 0

    5 | 50 | 0

    6 | 40 | 0

    ---+--------------+--------------

    After third iteration and so on......

    BucketID | FullCapacity | CurrentAmount

    ---+--------------+--------------

    1 | 85 | 0

    2 | 80 | 80

    3 | 75 | 35

    4 | 70 | 0

    5 | 50 | 0

    6 | 40 | 0

    ---+--------------+--------------

    sorry...but at the moment i am at a loss as to why you wish to store each iteration....can you please explain the business requriement behind this?

    Sure, actually it is a matrix. I want to preserve the matrix and store each cell as there are calculation to be done on each cell. Imagine it as a matrix where bucket table is on X axis and Filler table is on Y axis. After each iteration we will fill one or more cell. hope that explains.

    What would certainly help would be a data structure with before and after figures.

    The post above shows the same rows & columns of the same table processed in cycles. If this is what you want, then it's back to the original, looping through the values in the filler table.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden