Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Database and Reporting > Limit Rows Returned from SQL Stored Procedure


Reply
 
Thread Tools Display Modes
  #1  
Old 02-05-2004, 12:49 PM
hdsjunk hdsjunk is offline
Freshman
 
Join Date: Sep 2003
Posts: 43
Lightbulb Limit Rows Returned from SQL Stored Procedure


I have a VB6 application that allows the user to provide criteria that is sent into parameters of a SQL stored procedure. The stored procedure selects records based on the criteria, and returns the data to a disconnected recordset in VB. My issue is that some of the recordsets being returned are very large, thus the stored procedure runs slow. My questions is this:

Is there any way to tell the stored procedure to only return so many, and then somehow in VB, tell it to get the next batch of records when needed? I'm assuming maybe by using fetch or something? I am pretty desperate at this point, so any advise, code snippets, or other links would be more than appreciated.

Thank you!
Reply With Quote
  #2  
Old 02-05-2004, 04:32 PM
Optikal's Avatar
Optikal Optikal is offline
Codeaholic

Retired Leader
* Guru *
 
Join Date: Oct 2002
Location: Winnipeg, MB, Canada
Posts: 4,543
Default

If your using Oracle as your database you can use a filter on rowid, but as far as I know Oracle is the only DBMS that supports that.
__________________
There are 10 types of people in this world, those that understand binary, and those that don't.
Reply With Quote
  #3  
Old 02-05-2004, 10:32 PM
VBJoe's Avatar
VBJoe VBJoe is offline
Village VB Idiot

* Expert *
 
Join Date: Jan 2003
Location: Idaho
Posts: 1,850
Default

I've run into this problem before, and I haven't found an easy solution.

I don't know what Database engine you're using, but if you're using SQL Server, you can try this little trick:
1) In the Stored Procedure, rather than returning all those records, populate them into a temporary table that has a separate identity field.
2) In your code, build a query that uses TOP to return only the first x rows from the temporary table, then do what you need to with those records.
3) Find the value of the last record returned, and write a DELETE query that kills every record before that one.
4) Repeat steps 2 and 3 until you run out of rows to process.

I know that it seems a little clunky, but I've actually used this technique successfully.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ADO Data control & Stored procedure at the SQL server rachello99 Database and Reporting 1 06-11-2003 07:48 AM
SQL Stored Procedure from VB surfinbird Database and Reporting 5 04-25-2003 08:33 AM
Binding recordset returned by stored procedure to Dbgrid ssharrock Database and Reporting 2 08-19-2002 09:30 PM
Creating Access Databases TomGuy Database and Reporting 8 07-10-2002 10:56 AM
SQL Stored Procedure Response byrne1 Database and Reporting 3 06-21-2001 08:44 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->