BUG: Precision and Scale Change with SUM or AVG Functions

Last reviewed: April 28, 1997
Article ID: Q167602
The information in this article applies to:
  • Microsoft SQL Server, versions 6.0 and 6.5
BUG #: 15699 (NT: 6.00)
       16647 (6.50)

SYMPTOMS

If a SUM or AVG function is applied to a numeric field, the field looses its precision and scale.

WORKAROUND

Use the CONVERT function to regain the precision and scale.

For example, in a case where a cursor declared to select AVG(<column>) and fetch fails with error 16923, declare the cursor like the following:

   declare cur_test cursor for
   select convert(numeric(<precision>,<scale>),AVG(c1))
   from table1

STATUS

Microsoft has confirmed this to be a problem in Microsoft SQL Server versions 6.0 and 6.5. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

With a limited amount of testing, the SUM function seems to get a precision of 38 and retains the scale. The AVG function seems to get a precision of 38 and a scale of six if the original scale was less than six; otherwise, it retains its scale. This problem does not occur with MAX or MIN functions. You can observe this behavior with a table created with select into or with a view.

When you are trying to use a server side cursor to fetch the SUM or AVG of a numeric column, this problem causes error 16923:

   Cursorfetch: Maximum length of '%s' is incompatible with that of
   selected column in the cursor.
 

	
	


Keywords : kbbug6.00 kbbug6.50 kbusage SSrvTran_SQL
Version : 6.0 6.5
Platform : WINDOWS
Issue type : kbbug
Resolution Type : kbworkaround


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: April 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.