Hi, i m serious freelancer with 100% completion rate and i believe i can help you. I've done hundreds of sql projects (many of them using stored procedures) and i've never had a single problem. If you are interested please message me and i will try to create you procedure so you can test it. As i said i m serious freelancer and i've never took a single dollar unless my solution was perfect.
Edit: I already wrote it, if you can, just message me and i will send it to you for testing.
Thanks, Milan