I'll try to simplify here since the code is thousands of lines long and unnecessarily complex. (not my code.)
What I have is a stored procedure that builds SELECT statements based on literally hundreds of variables and then runs them. I don't wish to duplicate the logic (or even try to understand the logic) of the SP, I just want to take the output and put it into tables. SO, I have copied the SP and I am adding table variables and trying to populate them with the results of the SELECT statements.
I have declared a table named @egbs_1 and I have put the SELECT statement into a string which I am running with sp_executesql.
When I run it, I keep getting this error:
SO, my questions are; Should my @egbs_1 table variable be out of scope? And, what am I missing here?
What I have is a stored procedure that builds SELECT statements based on literally hundreds of variables and then runs them. I don't wish to duplicate the logic (or even try to understand the logic) of the SP, I just want to take the output and put it into tables. SO, I have copied the SP and I am adding table variables and trying to populate them with the results of the SELECT statements.
I have declared a table named @egbs_1 and I have put the SELECT statement into a string which I am running with sp_executesql.
Code:
SET @newsql_1 = 'INSERT INTO @egbs_1 VALUES ( ' + @newsql_1 + ' )'
EXEC sp_executesql @newsql_1
SELECT * FROM @egbs_1
When I run it, I keep getting this error:
SQL:
Msg 137, Level 15, State 2, Line 1
Must declare the variable '@egbs_1'.
SO, my questions are; Should my @egbs_1 table variable be out of scope? And, what am I missing here?