Replace cursors with queries
问题 Let's say I have a booking covering 6 hours and 3 discounts covering 2 hours each. I want to split my booking into 3 parts so I can allocate 2 hours per discount. It would return something like this: BookingId 1 | DiscountId 1 | Qty 2 BookingId 1 | DiscountId 2 | Qty 2 BookingId 1 | DiscountId 3 | Qty 2 I would then insert those records this into another table. I'm using an heavily optimized query to determine the number of hours available for each discount. However, I can't find a "good" way