Reputation: 197
How can I write a SQL stored procedure for getting top n records from stored procedure?
ALTER PROCEDURE GetRe
(@a INT, @b INT)
AS
BEGIN
DECLARE @Sum INT
SET @Sum = @a + @B
SELECT TOP @Sum *
FROM Customer
END
I'm getting an error:
Incorrect syntax near '@Sum'
Upvotes: 1
Views: 47
Reputation: 16917
Based on the error, it looks like you’re using SQL Server.
You need to wrap the @Sum
in parenthesis:
SELECT TOP (@Sum) *
FROM Customer
Upvotes: 4