Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Select Top (variable)

Author  Topic 

jgallen23
Starting Member

17 Posts

Posted - 2007-01-02 : 19:13:57
Is there any way to pass a variable to return the top X number of rows?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-01-02 : 19:35:11
http://www.sqlteam.com/item.asp?ItemID=233

Tara Kizer
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-02 : 20:27:24
Since this is now a SQL2005 forum, the solution is very easy.

SELECT TOP (@Number) * FROM <YourTableNameHere>


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-01-02 : 22:01:42
Ahhh, didn't notice that. I'll have to pay more attention to the forum names now.

Tara Kizer
Go to Top of Page
   

- Advertisement -