When I run a matched stored procedure, for example, above, in SSMS, I can get the data, as you mentioned in the procedure. However, if I try #tmptable , just like you, I also get the same error, because DROP TABLE removes it. From what I can say, import / export is basically the final INSERT process. The reason it works with a table variable is because the data still exists in the last insert; in the case of DROP TABLE this is not so. For example, when I delete a DROP TABLE , it works.
Maybe I'm wrong, but itβs logical when importing or exporting in the case of the above procedure
INSERT data
SELECT data
DROP data
INSERT (import / export): this generates "Invalid tmptable object name" "
With a variable (or no DROP ), this
INSERT data
SELECT data
INSERT (import / export)
In the second case, the data still exists. In the first case, they disappeared. In one case, if you want to use #tmptable, run your code with
IF OBJECT_ID('tempdb..#tmptable') IS NOT NULL DROP TABLE
Kprof source share