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
 Retrieve Specific number of records

Author  Topic 

peaceworld
Starting Member

1 Post

Posted - 2008-03-05 : 07:59:59
Hi,
How to display specific number of records? That means I want to display records starting from 3th row to 5th row. Please send your suggestions or links.
Table
-----
Name Age
-----------------
Raja 23
Kumar 26
Suresh 30
Rani 22
Subha 32
Ganesh 25

The result will be
Name Age
-----------------
Suresh 30
Rani 22
Subha 32

Thanx.

GANESAN MURUGESAN

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-05 : 08:05:54
[code]SELECT t.Name,
t.Age
FROM
(SELECT ROW_NUMBER() OVER (ORDER BY PKCol) AS RowNo,
Name,
Age
FROM YourTable
)t
WHERE t.RowNo >=3 AND t.RowNo <=5[/code]
PKCol is Primary key of your table.
Please note that this works only in SQL 2005
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-03-05 : 08:14:17
Also search for pagination

Madhivanan

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

- Advertisement -