The optimizer that is used to create plans for prospective execution plans does not execute T-SQL. It runs instructions through an algebraist, a process described earlier that is responsible for checking the names of database objects.
Since the request has not yet been completed, the temporary table does not yet exist. This is the cause of the error.
One way to solve this problem (and check the execution plan) is to create the #temp table and create insert into instead of select ... into in the stored procedure.
source share