PRB: Query to a Report Causes an Inaccurate Sum or CountLast reviewed: April 30, 1996Article ID: Q120187 |
The information in this article applies to:
- Microsoft Visual FoxPro for Windows, version 3.0 - Microsoft FoxPro for MS-DOS, versions 2.0, 2.5x, 2.6, 2.6a - Microsoft FoxPro for Windows, versions 2.5x, 2.6, 2.6a - Microsoft FoxPro for Macintosh, versions 2.5x, 2.6 - Microsoft FoxPro for UNIX, version 2.6
SYMPTOMSWhen you are running a query to a report using two or more databases with a one-to-many relationship and the report is counting or performing other math functions on fields from the parent database, the count or value from the math functions is inaccurate.
RESOLUTIONTo get an accurate count, you need to create a user-defined function (UDF). For an example of a UDF that produces the correct count, see "Workaround" in the "More Information" section below.
MORE INFORMATIONWhen the report performs a count or any math function, it looks to the source database for its information. If the data comes from a query, the source is a temporary table called QUERY. If the query had two or more tables in it with a one-to-many relationship, there will be a matching parent field for each child field.
Steps to Reproduce Problem
WorkaroundTo obtain the correct count, you can use the following UDF.
FUNCTION mycount PARAMETERS x recnum = RECNO() mygroup = state SELECT DISTINCT customer.cno, customer.state; FROM customer, invoices; WHERE invoices.cno = customer.cno; AND customer.state = mygroup; INTO CURSOR counter COUNT TO x SELECT QUERY GO recnum RETURN x REFERENCESFoxPro for Windows "Getting Started," Chapter 9 FoxPro for Windows and MS-DOS "Language Reference," page L3-1114
|
Additional reference words: VFoxWin 3.00 FoxUnix FoxMac FoxDos FoxWin 2.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |