ACC: Using Query to Return Every Nth Record from a Table (95/97)Last reviewed: March 2, 1998Article ID: Q180662 |
The information in this article applies to:
SUMMARYAdvanced: Requires expert coding, interoperability, and multiuser skills. This article shows you two methods that you can use to return every Nth record from a table. The first method is the simplest and uses an AutoNumber field. But this method is not always reliable. The second method is a little more complex, but it is reliable. It uses a dynamic counter in a query.
MORE INFORMATION
Method 1You can create a query based on a table that contains an AutoNumber field with the criteria Like "*0" on the AutoNumber field to return every 10th record. Similarly, you can use the criteria Like "*00" to return every 100th record. You can also use the Mod operator to return every record whose AutoNumber field is evenly divisible by any other number. The problem with this method is that it only returns matching values. It is not dependent on the physical position of the records within the table. If there are gaps between the values in the AutoNumber field because records have been deleted, you won't get an accurate representation of every Nth record.
Method 2This method uses a dynamic counter and does not require an AutoNumber field in the table. CAUTION: Please familiarize yourself with the issues when using a dynamic counter in a query as described in the following article in the Microsoft Knowledge Base before continuing with this method:
ARTICLE-ID: Q94397 TITLE : ACC: Adding Dynamic Counter to Query to Count RecordsCAUTION: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and perform these steps on a copy of the database.
|
Additional query words:
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |