SELECT TOP @var * FROM table

November 23, 2005

MS SQL 2000 doesn't allow you to have declared variables in the TOP x statement. Found this nice little way around this, you basically use SET ROWCOUNT command:

declare @v1 int
set @v1 = 25
set rowcount @v1
select * from MyTable Order by DateColumn
set rowcount 0

MS SQL 2005 actually allows you to do this directly and I remember being at the product demo and all the 'ohhhs' and 'ahhhs' came out for that one!

diigo itdeliciousdiggfacebookreddit

Comments

blog comments powered by Disqus