Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting Middle Entries

Status
Not open for further replies.

fpgiv

Programmer
Oct 1, 2003
91
US
Hi,
I know that with sql, you can return the top 10, 20 or whatever number of values you need from a table. Is there a way to bring back the middle entries from a query. For example, instead of bringing back the first 20 entries of a query, I would like to bring back the 11th through 20th entries.
Is this doable?
Thanks!
~Phil
 
BTW, mwolf00's method seems to be equally fast unless I select all columns in which case it's 60% slower. Don't understand that.
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
A bit of serendipity, does it count if it's the result of not being too smart? The code with the @First and @Last runs twice as fast as the code with @First and top 10,000. Who would know?
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Weird! Are you measuring this by SQL Profiler or by just plain time to run?

I think there's a cost with ordering that I never considered before.

About the fuzziness, I thought of that too when working on the problem myself... but filed it away for future thought because the problem was specific numbers, not groups touching the boundaries.
 
Ahh...Profiler...ahh what's that? Isn't time to run good enough?
On the specific numbers: it seems like it's only an academic question, the more likely real world problem is to bring back disconnected recordsets of batches of reasonable size from the server.
So what do your Profiler tests show?
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Have a Happy New Year Esquared, tell your boss that you are taking the rest of the year off to get some rest. :)
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
So where's the performance tests? Have I found the Holy Grail? The solution that not only is NOT a single query, but is easier to understand and faster to boot!
Am I finally vindicated for my [soapbox]BOXING!
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
I'm busy with important stuff!!!

Seriously, I have a ton of work right now, am busy in the evenings with my fiancée and houseguests and wedding plans and all sorts of things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top