Solved

SQL only return range of records

Posted on 2008-10-23
4
543 Views
Last Modified: 2013-11-25
Is there sql to only return back a range of records i.e from 20-30 in access.  or are there any easy work arrounds to this problem

thanks

dave
0
Comment
Question by:david_88
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 46

Expert Comment

by:tbsgadi
ID: 22784452
Hi david_88,

Something like
SELECT * FROM Table1 WHERE ((Table1.ID) Between 20 And 30);

Good Luck!

Gary
0
 
LVL 6

Accepted Solution

by:
cr4ck3rj4ck earned 500 total points
ID: 22784477
In MySQL you can use the LIMIT function but in MSACCESS you have to use a sub query to create an offset.

select top X * from myTable where id not in (select top Y * from myTable)

X would be replaced by the amount of records you wanted to return.
Y would be replaced by the position within the data set at which you wanted to start.
id would be your unique identifier within the table.

For example:
select top 10 * from myTable where id not in (select top 19 * from myTable)

That would return records 20-30 in a recordset.
0
 
LVL 5

Expert Comment

by:eridanix
ID: 22784598
Hi,

this is example of SQL paging. You can simply modify it as you need:

top_onPage = "TOP " + Convert.ToString((onPage * page > totalCount) ? (totalCount % onPage) : (onPage));
top_page = "TOP " + Convert.ToString(onPage * page);

SELECT * FROM (
      SELECT TOP " + top_onPage + " id  FROM (
            SELECT DISTINCT " + top_page + " T.id
                  FROM dbo.tblTest T
            )      as A ORDER BY X ASC
)      as B ORDER BY X DESC
0
 

Author Closing Comment

by:david_88
ID: 31509138
perect  thanks!
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 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