This question already has answers here:
Dynamic SELECT TOP @var In SQL Server (6 answers)
Closed yesterday.
I need to write a stored procedure like this but I get an error
Expecting '(', INTEGER, NUMERIC or REAL
This is my procedure code:
CREATE PROCEDURE [dbo].[myStoredProc]
@numberOfRows int
AS
BEGIN
SELECT TOP @numberOfRows *
FROM dbo.myStoredProc
END
Thank you!
1条答案
按热度按时间juud5qan1#
You're very close - you just need to put the parameter value into brackets - like this:
Also, you need to provide a valid table name for your
FROM
clause - you cannot select from the stored procedure you're just executing - that would be an endless loop in the making ....See the official MS documentation on
TOP
for more details