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
 How to retrieve specific number of records?

Author  Topic 

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2010-12-22 : 10:16:47
Hi,

I m querying DB according to some inputs from user. There is a field, Number of Records if user enters lets say 20, i would like to retrieve 20 records from the query.
Is this possible?


Thanks in advance.

Best Regards

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-12-22 : 10:25:56
use the TOP clause with a variable

declare @row int
set @row = 20
select top (@row) * from yourTable

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-12-23 : 03:04:15
Also add a Order by clause

Madhivanan

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

- Advertisement -