I keep getting an error with the following stored procedure. I had it working correctly using EXEC, then I switched to sp_executesql and I haven't been able to get it to execute. I keep getting the following error: Incorrect syntax near '@numberOfItems'.
ALTER PROCEDURE dbo.FetchResourcesToProcess
(
@tableName nvarchar(MAX),
@numberOfItems int
)
AS
BEGIN
DECLARE @SQL nvarchar(MAX);
SET NOCOUNT ON;
SET @SQL = N'Select TOP @numberOfItems * from ' + @tableName + N' where Active = 1 AND BeingProcessed = 0'
EXEC sp_executesql @SQL, N'@numberOfItems int', @numberOfItems
END
Tablename is a string structured as follows: "[TABLENAME]".
Thanks