Go to home page mail me! RSS Feed
FoxMetrics Web Analytics

SELECT TOP(X)

Wednesday, March 01, 2006 10:55 PM

One of the cool new features of SQL Server 2K5 is the ability to use a variable as the top count value. In the days of SQL Server 2K, your stored procs had to hold the hard coded value, so it was a pain if you wanted your application to dynamically pass the number of rows to return. Here is an example using SQL Server 2000.

SELECT TOP 15 * FROM TableName

...with SQL Server 2005 we can use a variable:

DECLARE @TopRows INT
SET @TopRows = 15

SELECT TOP ( @TopRows ) * FROM TableName

Your Comments.

No comments posted yet.

Your Reply.

Comment Form.

Fields denoted with a "*" are required.

You may also like to leave your email or website.

 
Please add 2 and 4 and type the answer here:

Preview Your Comment.

 
Next entries »