FIX: Dividing 0 by a Negative Decimal or Numeric Number Results in -0

Article translations Article translations
Article ID: 285544 - View products that this article applies to.
This article was previously published under Q285544
BUG #: 203148 (SHILOH_bugs)
Expand all | Collapse all

SYMPTOMS

When using decimal or numeric data types, if you divide 0 by a negative number, a negative 0 (-0) is returned.

RESOLUTION

To resolve this problem, obtain the latest service pack for SQL Server 2000. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
290211 INF: How to Obtain the Latest SQL Server 2000 Service Pack

WORKAROUND

Check for 0 before you perform the division and avoid the division if 0 is involved; for example:
declare @v1 dec(10, 2), @v2 dec(2, 1), @v3 dec (10,2) 
-- @v3 is the result of @v1/@v2
select @v1 = 0.0, @v2 = -1.0
if @v1 = 0  
   select @v3 = 0.0
else
   select @v3 = @v1 / @v2
				

STATUS

Microsoft has confirmed that this is a problem in SQL Server 2000. This problem was first corrected in SQL Server 2000 Service Pack 1.

MORE INFORMATION

SQL Server does not consider the computed value (-0) equal to 0, so the comparison of the computed value (-0) with 0 fails. For example, the following code
   declare @v1 dec(10, 2), @v2 dec(2, 1)
   select @v1 = 0.0, @v2 = -1.0
   if @v1 / @v2 = 0  
      print 'equals zero'
   else
      print 'not equal zero'
				
Gives the following result:
   not equal zero 
				
For additional information about related bugs in SQL Server 7.0, click the article number below to view the article in the Microsoft Knowledge Base:
275608 FIX: Mathematical Operations on Numeric or Decimal Columns with Negative Numbers May Return Unexpected Results

Properties

Article ID: 285544 - Last Review: October 16, 2003 - Revision: 3.2
APPLIES TO
  • Microsoft SQL Server 2000 Standard Edition
Keywords: 
kbbug kbfix kbsqlserv2000sp1fix KB285544

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com