Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/105141

From BetaArchive Wiki

How to Get Latest Invoice for Each Customer Number

ID: Q105141

The information in this article applies to:

  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, and 2.5a
  • Microsoft FoxPro for Windows, versions 2.5, and 2.5a

Customers frequently ask how to pull certain information out of a database that is the latest or most current information, usually based on some other field that may be duplicated in the same database.

While there are many different methods that might be employed, including using DO WHILE loops, creating a program or procedure with the following SELECT statements will achieve the quickest result (the INVOICES.DBF file in the TUTORIAL subdirectory has been used in this example because it gives a good approximation of this type of database structure):

   SELECT invoices.cno, MAX(invoices.idate) AS idate
      FROM invoices;
      GROUP BY invoices.cno;
      INTO cursor temp

   SELECT invoices.*;
      FROM invoices, temp;
      WHERE invoices.cno = temp.cno;
      AND invoices.idate = temp.idate;
      ORDER BY invoices.cno

These statements will automatically generate a Browse window with the desired result. Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a KBCategory: kbprg KBSubcategory: FxprgBrowse

Last Reviewed: June 27, 1995
© 1999 Microsoft Corporation. All rights reserved. Terms of Use.