S
So, for the curious ... ST and SB are in MSL. Everything else is in MM.This entire system is some sort of bastardized message triggering engine. It loads data from an external source, munges it repeatedly, and then creates triggers that are picked up by another program. However, somewhere along the way, the "target" program switched from a third party utility to something written in-house by the same guy who wrote this query, with predictably train-wreck changes as a result. For example, this HAVING SUM CASE bit is in here because some triggers are now intended to be viewed by multiple people. R and RT combine to identify individual employees, or groups of employees, depending on some magic numbers. ST = 3 is a magic number that (I think) represents that the trigger has been cleared or deleted or whatever, so should never re-appear ... but it's handled per-viewer because no matter how many people see a message, there's just the one copy of it.I don't think this is even the worst WTF in this system, and I've only scratched the surface. Counting the in-house "target" program, there's probably 50,000 lines of code involved here.