I have a report (SP) on global views that union 10 companies.
Now I took the monthly backups of these companies and try the same on the last 6 month.
So each view has about 60 'UNION ALL' from the different databases.
And get the above error.
I rebuilt the views for two month, the error is gone.
Now I set the views back to 6 month, and split the major query in the SP, running seperatly each select. No error.
It seems it doesn't matter where you split the query, just let it produce two execution plans.
For me it was simple to do two Insert into #TmpTable.