PRB: SUM in SQL Does Not Return Number with Decimal Places

Last reviewed: June 27, 1995
Article ID: Q124401
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6, 2.6a
  • Microsoft FoxPro for MS-DOS, versions 2.5, 2.5a, 2.5b, 2.6, 2.6a
  • Microsoft FoxPro for Macintosh, versions 2.5b, 2.5c, 2.6a
  • Microsoft FoxPro for UNIX, version 2.6

SYMPTOMS

When using the SUM, MIN, or MAX commands in an SQL SELECT statement with the conditional IIF command, sometimes the resulting expression will not return the correct number of decimal positions. This is a problem only when the number returned should have decimal places but does not. For example, the following command returns an integer number if the first record does not meet the true condition of the IIF statement.

   SELECT SUM(IIF(ytdpurch > 20, ytdpurch, 0)) FROM customer


CAUSE

The SELECT statement looks at the format of the number after reading the first record. Because the first record in this case doesn't meet the true part of the IIF condition, a zero is placed as the first number to be summed because that is the false part of the IIF condition. The format of the 0 in the conditional IIF doesn't have decimal places. Therefore the format for that field in the query will not have decimal places.

WORKAROUND

If the false part of the IIF is given decimal places, such as 0.00, the SUM statement of the SELECT command will have the correct numerical structure.

STATUS

This behavior is by design.


Additional reference words: FoxWin FoxDos FoxMac FoxUnix 2.50 2.50a 2.50b
2.50c 2.60 2.60a
KBCategory: kbprg kbprb
KBSubcategory: FxprgSql


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

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