SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 selecting a specified number of rows
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

luke nukem
Starting Member

Ireland
5 Posts

Posted - 07/30/2007 :  09:06:53  Show Profile  Visit luke nukem's Homepage  Reply with Quote
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

Sweden
30208 Posts

Posted - 07/30/2007 :  09:11:38  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

India
22754 Posts

Posted - 07/30/2007 :  10:13:48  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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

India
22754 Posts

Posted - 07/30/2007 :  10:15:32  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000