I have a procedure which returns the error:
Must declare the table variable \"@PropIDs\".
But it is followed with the message:
Change you code to :
Declare @ProductsSQL nvarchar(max);
SET @ProductsSQL = 'DECLARE @PropIDs TABLE
(ID bigint);
Insert into @PropIDs (ID)
SELECT [WPRN] FROM [dbo].[Properties] WHERE(WPRN in (' + @NotNeededWPRNs + '))'
exec sp_executesql @ProductsSQL
Table variable declared outside the dynamic SQL will not be available to the dynamic SQL.