I posted this article on CodeProject.com a while back. The problem it solves, comes up from time to time. I wrote it, as part of the online donations site, for SunnyBrook Hospital Foundation. The system accepted the donation, and would automatically generate a PDF of the official tax receipt for Charitable donations.
I also posted code for load-testing, in the ‘comments’ section on that page.
https://www.codeproject.com/articles/Flexible-numbering-sequences-in-T-SQL