I am normally ardently against using cursors whenever possible. However, a recent project I've been tasked with has me wondering when it is OK to break this rule.
I work for a school district. There are some circumstances when a student is exempt from having to pay certain fees. I need to write a stored procedure that will run nightly that identifies students that have qualified for exempt fees. Any existing fees for these students must be exempted. Any payments the student has made on exemptable fees (not all fees are exemptable) need to be voided. Payment amounts made toward these fees need to go into the student's account as a deposit. Then, if there is money left over in the student's account and they have non-exemptable fees still outstanding, the surplus needs to be applied as payment automatically to these fees (in order of oldest to newest). Each payment made this way naturally then needs to be debited from the student's account. When the procedure initially runs, it will be cleaning up only about 300 or so students. Once it is running nightly, it will likely be operating on 0-10 students per night (0 more often than not).
There are set based solutions to this problem. However, they are very complicated and hard to grok if you are seeing the code for the first time. Using cursors, the code is much simpler, easier to read, and easier to test. Also, if I were to use cursors, the development time would be significantly reduced compared to writing a set based solution.
I guess my question is this: Are these good reasons to use a RBAR approach given that performance is not really going to be an issue? Part of me feels like it's a no-brainer to go with the easier solution, but the other part of me feels like that first part of me is just lazy. I'm wondering what other people think about this situation and what they do when faced with similar design decisions.
↧