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
 General SQL Server Forums
 New to SQL Server Programming
 selecting a specified number of rows

Author  Topic 

luke nukem
Starting Member

5 Posts

Posted - 2007-07-30 : 09:06:53
I know I can use "First" to specify a number of rows to return from a query but is it possible for the number of rows returned to be based on a parameter, something like this:

SELECT FIRST @someNumber name, age
FROM friends
WHERE age > @ageInput

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-30 : 09:11:38
SELECT TOP (@SomeNumber) Name, Age
FROM Friends
WHERE Age >= @AgeInput




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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-30 : 10:13:48
Also using ORDER BY clause will make it more sense

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-30 : 10:15:32
If you use SQL Server 2000 then use

SET ROWCOUNT @SomeNumber
query
SET ROWCOUNT 0


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -