Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 30th, 2003, 11:20 AM
Registered User
 
Join Date: Nov 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ramanuj Send a message via Yahoo to Ramanuj
Default Retreive 90th -100th rows from a query

I have a set of tables with almost 2,00,000 records each.
I want to search for a particular condition using JOIN and
THEN retreive only 20th - 30th record; and not all.

I can use TOP 10 to get 1-10th record; but that doesn't
solve my purpose as I display the records in a Webpage
with 10 records each page; and when the user is in the 9th
page i got to display 90th - 100th record; and so on.


DONT want to use cursors.
Is there any hidden row returned by SQL 2000 which
contains Serial Number; i.e the record position which
helps me to achieve it.
 
Old November 30th, 2003, 12:13 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Take a look at this article: http://www.4guysfromrolla.com/webtech/062899-1.shtml

It describes custom paging using a Stored Procedure. The downside of the solution explained in this example is that a copy of the original data is made, every-time you call the procedure. No fun with 2,000,000 records ;) You could decide to create a permanent copy of the data, purely for your data navigation. Depending on the app and database you have, this may work pretty well or it may turn out to be a maintenance nightmare ;)


Take a look here: http://www.adopenstatic.com/experime...dsetpaging.asp for a discussion on various paging methods and their speed.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old November 30th, 2003, 12:50 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Is there a column which orders the data? If so, you might be able to use a technique where you SET ROWCOUNT equal to the number of rows you want to return (e.g. 10), or use the TOP clause, then construct a WHERE clause which selects all rows whose ordering column value is greater than a parameter. Start with the parameter value less than the smallest legal ordering value. When you execute the procedure that displays the first set of rows, remember the ordering value of the last row you displayed, and use this as the parameter for the next fetch. Repeat as necessary.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old December 1st, 2003, 03:07 AM
Registered User
 
Join Date: Nov 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ramanuj Send a message via Yahoo to Ramanuj
Default

Quote:
quote:Originally posted by Jeff Mason
 Is there a column which orders the data? If so, you might be able to use a technique where you SET ROWCOUNT equal to the number of rows you want to return (e.g. 10), or use the TOP clause, then construct a WHERE clause which selects all rows whose ordering column value is greater than a parameter. Start with the parameter value less than the smallest legal ordering value. When you execute the procedure that displays the first set of rows, remember the ordering value of the last row you displayed, and use this as the parameter for the next fetch. Repeat as necessary.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com


Thanks Jeff.
I have a small Problem. If the user goes to 10th page by clicking the hyperlink from 2nd page, my last row displayed value would not help !!!

cheers,
Ramanuj
 
Old December 1st, 2003, 07:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes. Allowing the user to 'bounce around' makes thing much more difficult. I was assuming just a forward paging movement through the data. Sorry.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Query on million of rows wkm1925 SQL Server 2000 6 October 23rd, 2006 09:30 AM
How to check whether query retuns some rows or not kumar_raj13 ASP.NET 1.0 and 1.1 Professional 1 March 13th, 2006 12:59 AM
Query That Return 0 Rows in Results nimrod_r BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 June 5th, 2005 02:14 AM
getting a query rows as columns raamts SQL Language 1 February 24th, 2005 04:06 AM
SQL Query to Convert Columns into Rows Niaz SQL Server 2000 2 April 20th, 2004 01:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.