SQL Server 2005实际上允许我们使用变量、表达式或语句参数化TOP子句。所以你可以这样做:
SELECT TOP (@foo) a FROM table ORDER BY a
SELECT TOP (SELECT COUNT(*) FROM somewhere else) a FROM table ORDER BY a
SELECT TOP (@foo + 5 * 4 / 2) a FROM table ORDER BY a
-- Works in all versions
SELECT TOP 10
-- Does not work on 2000
SELECT TOP (10)
SELECT TOP (@rows)
-- Works in both 2ooo and 2oo5
SET ROWCOUNT @max
SELECT *
FROM ...
SET ROWCOUNT 0