Hello,
I have a requirement of assigning sequential Numbers to students. The problem is the data must be partitioned by course first and then the Number must be assigned starting from say 1 to say 1000.
Each Course should have at least a gap of say 20 ( may differ ) to accommodate a student in the same course in case, someone, if left out as of now appears later.
| S.No | StudentID | RollNumber | Course | ToBeAssignedRollNumber |
| 1 | 123 | NULL | A | 1 |
| 2 | 124 | NULL | A | 2 |
| 3 | 125 | NULL | A | 3 |
| 4 | 126 | NULL | B | 24 ( 20 Gap for later accomodation) |
| 5 | 127 | NULL | B | 25 |
| 6 | 128 | NULL | B | 26 |
| 7 | 129 | NULL | C | 47 (20 Gap for later accomodation) |
| 8 | 130 | NULL | C | 48 |
| 9 | 131 | NULL | C | 49 |
and so on.
I have tried partitioning and Recursive CTE but haven't succeeded to get this kind of series for assigning finally the RollNumber.
Any help would be very much anticipated.
Thank You.