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 2000 Forums
 Transact-SQL (2000)
 dynamic sql top x

Author  Topic 

qwertyjjj
Posting Yak Master

131 Posts

Posted - 2008-07-22 : 06:31:32
Is it possible to select the top number dynamically?
DECLARE @a int
SET @a = 50

SELECT TOP @a * from TABLE ?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-22 : 06:45:49
SET ROWCOUNT @a

SELECT * FROM Table

SET ROWCOUNT 0



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-07-22 : 06:50:17
select TOP(@a) *
from yourTable
order by SomeColumn

Em
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-22 : 06:55:17
Em, this is a SQL Server 2000 forum.
What you posted is the preferred way in SQL Server 2005 and later.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-07-22 : 07:20:40
doh!

Em
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-22 : 07:36:24
Yes!

They will make a second Simpsons movie.


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -