Execution plan over query with temp tables
SET SHOWPLAN_TEXT ON
(or clicking on Display Estimated Execution Plan is SSMS) creates a plan instead of executing the SQL
Since this creates the #temp
SELECT Id
INTO #temp
FROM table
WHERE ...
this will fail
DELETE FROM #temp
INNER JOIN table2 ON a=b
WHERE ...
So solution is to add this to the top (or do the equivalent via SSMS)
SET SHOWPLAN_TEXT OFF
GO
SET STATISTICS PROFILE ON
GO
It should let you see the estimated execution plan for the first statement fine.
For the second statement you will need to create and populate the #temp
table first (population is important so that it shows you the plan that will be used for the correct number of rows).
(Or you can of course just turn on the "Include Actual Execution Plan" option in SSMS and run the whole thing if you aren't specifically trying to see the estimated plan)