È necessario inserire i dati da un'istruzione select in una tabella temporanea utilizzando il comando execute.Inserimento in una tabella temporanea da un comando Execute
if OBJECT_ID('tempdb..#x') is not null
drop table #x
Create Table #x(aaa nvarchar(max))
declare @query2 nvarchar(max)
set @query2 = 'SELECT [aaa] from IMP_TEMP'
INSERT #x
SELECT [aaa] from IMP_TEMP -- THIS WORKS
SELECT *from #x
INSERT #x
exec @query2 -- THIS DOES NOT WORKS, WHY?
SELECT *from #x
tabella La temperatura non è nella stessa portata di quello utilizzato per eseguire l'SQL dinamico. http://stackoverflow.com/questions/688161/tsql-writing-into-a-temporary-table-from-dynamic-sql/http://stackoverflow.com/questions/688161/tsql-writing-into-a- tabella-temporanea-da-dinamica-sql –
@AlexK: Queste domande riguardano una tabella temporanea in un ambito interno che l'OP vuole leggere in un ambito esterno. Questa domanda riguarda l'opposto, che non è un problema. – Andomar