SQL Server 2005 actually allows us to parameterize the TOP clause, using a variable, expression or statement. So you can do things like:
select top (@foo) [Column1] from [dbo].[myTable]
select top (SELECT COUNT(*) FROM somewhere else) [Column1] from [dbo].[myTable]
select top (@foo + 5 * 4 / 2) [Column1] from [dbo].[myTable]
so we can create parameterized stored procedure with top as input parameter. In Sql 2005 it's simple:
create procedure dbo.getFoo
@top INT
as
begin
select top (@top) percent [column1]
from [dbo].[myTable]
end
go