With the extent of man-hours to be spent on creating a custom resource like that, I would defer to an upgrade to 10.6 if it were me.
I'm positive this could be done in SQL, but without the data in my DB, I'm not much help on testing and creating it for you.
Clik here to view.
