In SQL Server 2005 and above, you can actually parameterize the top command.
Below is the code from MSDN
USE AdventureWorks; GO DECLARE @p AS int; SELECT @p=10 SELECT TOP(@p)* FROM HumanResources.Employee; GO
In earlier versions of SQL Server, you need to either use rowcount or dynamic sql.
source share