我需要使用执行命令将 select 语句中的数据插入到临时表中。
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