I'm following several examples to use global temp table such as this & this
I have following query to get data into a global temp table:
DECLARE @SQL NVARCHAR(MAX)
SET @SQL = N'SELECT * INTO ##tmpDraftTableData  
             FROM ' + @DraftTableName 
EXEC sp_executesql @SQL
Note that the @DraftTableName is dynamic and come from different table with different structure, that's why I need to use dynamic query.
And then I want to insert the data as obtain from above global temp table into another temp table to loop and process the data:
SELECT *
INTO #tmpDraftTableData
FROM ##tmpDraftTableData  -- ERROR: Invalid object name ##tmpDraftTableData
Seems like I can't use the global temp table with the error
Invalid object name ##tmpDraftTableData
unlike other sample code.
What did I do wrong here?
 
    