I was actually going to see if I could refactor it, but I'm not exactly a SQL pro (see what I did there?)
Thanks for sharing though! Even gave me something new to look at (SQL cases).
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.