Green

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 intset @top = 5

BEGINset rowcount @top select Some_ID from tblStuffset
rowcount 0END

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: