Solved

functionality similar to LIMIT x,y

Posted on 2003-11-19
8
341 Views
Last Modified: 2008-03-06
Hi,
I am building a website using asp and sql server and trying to implement a site search.
I want to show 20 search results per page as usual. But my problem is, not having LIMIT x,y at SQL server. I have 2 solutions in mind but can't decide which one is better or is there any other way.
1- Using stored procedures I will move the query results cursor to the starting limit I want and return only 20 rows to the user.
2- Using ado, I will open the ResultSet as forwardonly(suggestions expected here) and I will move to the row I want to start at.

I am wondering which one will be better from performance point of view and if there is a better solution I will be glad to learn about it.
Hoping to hear your suggestions
Thanks
0
Comment
Question by:mahara
  • 3
  • 2
8 Comments
 
LVL 29

Expert Comment

by:Nightman
ID: 9777546
Performance will depend on the size of the recordset, speed of the network (or web access) and available memory.

If this is a very large recordset, option 1 would probably be better. For small recordsets, you could go with option 2. Either way, I would reccommend using a stored procedure to retrieve the data - stored procedures are far faster than dynamic SQL statements.

Cheers
Night
0
 
LVL 34

Expert Comment

by:arbert
ID: 9779398
Either way, I would NOT use a cursort.  Make sure you have a primarykey on your table and use the primary key to "page" through the recordset by keeping track of your last primary key.

Brett
0
 
LVL 2

Author Comment

by:mahara
ID: 9791228
Hi Brett
Thanks for your reply but keeping track of a primary key is not a suitable solution for my situation.
For ex :
I have a table having a primary key X and I have a query like this
select X,Y from TableX where a=b order by someranking
then the result set will be something like
ROW  X   Y
1        1    a
.
20     2897   c
.
.
545     997  b
And I want to show 20 results per page. Then I cant keep track of a primary key.
What is your suggestion for a case like this?
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 34

Expert Comment

by:arbert
ID: 9791926
I do understand what you're asking above, what are you using for your front end?

Also, here is a good article using the primary key approach.
http://www.microsoft.com/sql/techinfo/tips/administration/resultset.asp
0
 
LVL 2

Author Comment

by:mahara
ID: 9792093
Thanks for your interest
I am using asp. It is for a web site, and  I have 3 days left to implement a site search :) And 6 days to finish the job, hope you understand the situation.
And I need a suitable solution for showing the results.
Thanks again
0
 
LVL 34

Accepted Solution

by:
arbert earned 50 total points
ID: 9793249
Sor you're using asp and not ASPX?  If you're using ASPX, you can use the builtin paging, if not, check this out:

http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20185242.html?query=page+recordset&searchType=topic
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
t-sql Joining Issue 10 40
Simple SQL query from two tables 13 54
TSQL query to generate xml 4 35
SQL - Copy data from one database to another 6 19
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question