• Here is a plan where its just the query encapsulated in SELECT * FROM ()

    Remember, if I run just the part inside the outer nesting it runs in under 5 minutes. I just left it running last night as described above and it ran for 23 hours without finishing.

    Thanks

    Edit: I also included an execution plan without the encapsulation. This is when the query runs in <5 minutes. I can't see a difference between the two.