BTW , the PMs in ubbt_USER_PROFILE.USER_TOTAL_PM is not synchronized with the real value , should it be considered as a bug ?
USER_TOTAL_PM holds the number of unread PM's.
Anyway, if you would require such cleanup procedures, I would opt not to just collect a bunch of queries, but to write some code for it.
You could break up a complex problem in very easy little steps.