Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2003

    Unanswered: How to fetch limited record from SQL Server like 20-40 records out of 20000 records


    I have 20,000 records in a table and i want to do paging in ASP.
    I have to display 20 records per page. I will take count(*) from table and divide it by 20 and display the no.of pages and give the links like page-1 page-2 and so on.

    If i click on page-2 it has to fetch only 20-40 records off 20000 records.

    If I use "Top 20 " key word, i will get first 20 records only. But I need to get 20-40 records.

    I know that we can achieve this in Oracle using the ROWNUM like the follwing query.
    "select * from tblPerson where ROWNUM>20 and ROWNUM<40".

    Is there any way to get the same in SQL Server7.0.

    If possible, please let me know.


  2. #2
    Join Date
    Jan 2003
    you've posted this question 3 times...and already had replies to it...if those replies aren't the answer you're looking for then post a reply back to it...don't keep posting the same question over and over.

  3. #3
    Join Date
    Jul 2002
    Village, MD
    Take a look on this example: it works fine

    @pagenumber - page # to show
    @pagesize - page size

    create table #tmp (id int identity,***)
    insert #tmp (***)
    exec('select * from yourtable')

    select @pages=CEILING(count(*)*1./@pagesize) from #tmp

    select *** from #tmp
    where id between @pagesize*(@pagenumber-1)+1
    and @pagesize*@pagenumber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts