Sql – How to do SELECT TOP @Param in a Stored Procedure

sqlstored-procedures

I'm trying to do the following in a proc, but getting an incorrect syntax error:

SELECT TOP @NumberOfResultsToReturn *

What am I doing wrong here? Thanks.

Best Answer

Add parenthesis:

SELECT TOP (@NumberOfResultsToReturn) *