I understand less and less. Why are you looking up the table name in sys.tables?
Previously you were asking about a plain SELECT *
from your temp table. Now you are joining two temp temp tables and you are aggregating the result, which I assume results in far less rows.
The query as such is somewhat dubious. Is GroupObjectID a unique key in the table #ObjectResolver_XML_usp_DateRange? If not, you are likely to get incorrect results. It may be better to rewrite it as:
SELECT P.Date AS [Date],P.ClientCode AS PoolCode,SUM(MarketValueBase) AS MV
FROM #Results_usp_DateRange P
WHERE EXISTS (SELECT *
FROM #ObjectResolver_XML_usp_DateRange F
WHERE F.GroupObjectId = P.GroupObjectId)
GROUP BY P.Date,P.ClientCode
Note also that I removed the NOLOCK hints. NOLOCK hints is nothing you should use as a matter of routine, and it's completely pointless to have them on temp tables.
Whether this rewritten query will run better, I don't know. But it can certainly help to define GroupObjectId as the primary key of the #ObjectResolver_XML_usp_DateRange table.. Assuming that it is unique, that is.
Did I understand correctly that the query in the last post runs for 15 minutes?
Can you share the actual execution plan for the query above? Please upload it to http://www.pastetheplan.com.