I am trying to run a dynamic SQL query on SQL Server 2008:
DECLARE @cmd nvarchar(MAX)
DECLARE @tempTBL TABLE(value1 float)
SET @cmd = 'insert into ' + @tempTBL + ' select value from table11 as tb1 inner join table2 as tb2 on tb1.id = tb2.id where tb1.id2=''active'''
EXEC (@cmd )
Must declare the scalar variable "@tempTBL".
'insert into @tempTBL ...'
You don't need to be using dynamic sql here at all.
declare @tempTBL table(value1 float) insert into @tempTBL select value from table11 as tb1 inner join table2 as tb2 on tb1.id = tb2.id where tb1.id2 = 'active'