This is a definition and related sample code:
This code demonstrates that table variables aren’t visible to inner levels in the call stack. The attempt to refer to the table variable from the dynamic batch generates error:
Msg 1087, Level 15, State 2, Line 1
Must declare the table variable "@T1".
DECLARE @T1 AS TABLE
col1 INT NOT NULL
INSERT INTO @T1(col1) VALUES(10);
EXEC('SELECT col1 FROM @T1;'); -- <-- is this the inner level?
Question: Is there any way to modify this code to avoid the error?