Say I have a table like this in SQL Server 2008:
id | name | qty
-------------------
1 | john | 1
2 | bill | 3
3 | mary | 2
4 | jill | 5
I would like to query this table and return 1 row for each batch of, at most, a quantity of 2. So, the result of the query would look like:
id | name | qty
-------------------
1 | john | 1
2 | bill | 2
2 | bill | 1
3 | mary | 2
4 | jill | 2
4 | jill | 2
4 | jill | 1
Can this be done neatly without using a cursor? Is this possible using unpivot?
By the way, the qty column can have a maximum value of 10.