Query Optimization Help – Takes over an hour to run
I tried to generate an actual plan but the software gave me an error.
Some of the comments in the code seem to indicate someone is at least aware of some of the problems, but major performance improvements will require a transition to a more relational and optimizer-friendly architecture. I'm sorry if that all sounds a bit negative, but there is an awful lot of code and query tree there, so the best I can do is point to the fundamental causes. Addressing those will probably be painful, and perhaps not even practical, but there we are.