sql - Inserting into a temporary table from an Execute command -
i need insert data select statement temporary table using execute command.
if object_id('tempdb..#x') not null drop table #x create table #x(aaa nvarchar(max)) declare @query2 nvarchar(max) set @query2 = 'select [aaa] imp_temp' insert #x select [aaa] imp_temp -- works select *from #x insert #x exec @query2 -- not works, why? select *from #x
you need parenthesis around @query2
variable. exec
command execute stored procedure, while exec()
function executing dynamic sql taken parameter.
insert #x exec (@query2) select *from #x
Comments
Post a Comment