I have the following code:
DECLARE @temp_table_1 TABLE (id int identity(0, 1), col_1 varchar(50)),
@txtVar VARCHAR(MAX)
INSERT INTO @temp_table_1
SELECT col_1 FROM table_1 -- This table_1 is a real table in the database.
Set @txtVar = 'SELECT * FROM @temp_table_1'
EXECUTE (@txtVar)
The error I get is
Declare variable @temp_table_1.
How can I fix this?
This article will help you get a basic ideas of dynamic sql.
EDIT
It is not possible to use table variables in a dynamic query.
You have to use temporary table or Use custom TABLE type.
Temporary table
Custom Table Type