t-sql loop through all rows and sum amount from column until value is reached
问题 I have a table containing the below test data: I now would like to fill a restaurant with 12 seating spaces. This should result in: Basically, I need to loop from top to bottom through all rows and add the AmountPersons until I have filled the restaurant. In this example: (first few rows: AmountPersons) 3+1+2+4 = 10 UserId 52 can't be added because they reserved for 3 persons, which would result in 13 occupied places and there are only 12 available. In the next row it notices a reservation