I have the below table:
| Account | Credit | Debt | Net | ItemCount | InvoiceNumber |
|---|---|---|---|---|---|
| AAA | 1300 | 150 | 1150 | 2 | 10 |
| AAA | 500 | 50 | 450 | 12 | 20 |
| AAA | 1800 | 650 | 1150 | 29 | 30 |
No record can have a higher count than 10 items so anything over 10 must be split into multiples of 10 until the last remaining value (which could be less than 10)
I am trying to automate this in SQL and have not been able to come up with an idea that works, I would like something to look at the above table and spit out the following:
| Account | Credit | Debt | Net | ItemCount | InvoiceNumber |
|---|---|---|---|---|---|
| AAA | 1300 | 150 | 1150 | 2 | 10 |
| AAA | 500 | 50 | 450 | 10 | 20 |
| AAA | 500 | 50 | 450 | 2 | 30 |
| AAA | 1800 | 650 | 1150 | 10 | 10 |
| AAA | 1800 | 650 | 1150 | 10 | 20 |
| AAA | 1800 | 650 | 1150 | 9 | 30 |
Any thoughts on how can this be accomplished?