Go to home page mail me! RSS Feed

SELECT TOP(X)

Friday, May 25, 2007 11:15 AM

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 = 15SELECT 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 1 and 4 and type the answer here:

Preview Your Comment.

 
Next entries »