I came across this the other day. Using SQL 2000 I could
not get a Top statement to work with a variable. I had forgotten that only with
SQL 2005 and higher could you do this trick. I found a good way around it, you
can read
about it here. Anyway this works on SQL 2000:
declare @top int
set @top = 5
BEGIN
set rowcount @top
select Some_ID
from tblStuff
set
rowcount 0
END
The code above would return the first five records from tblStuff. For any of
the newer SQL Server version you can simply use the @top variable in Top
like:
select top (@top) Some_ID
from tblStuff
Tags: SQL