A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi @Anonymous ,
Welcome to Microsoft Q&A!
You could also include the DDL of @temp in @alenzi in order to avoid this kind of error.
Please also refer below:
CREATE PROC Test
AS
BEGIN
DECLARE @sql NVARCHAR(MAX)
SET @sql = N' DECLARE @Temp Table (ID int, Name Varchar(50))
insert into @Temp
VALUES
(1, ''Adam''),
(2, ''John''),
(3, ''Andrew'')
SELECT * FROM @Temp'
EXEC(@sql)
END
Then call this procedure as below:
EXEC Test
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.