FIX: A query that joins two tables on smalldatetime data type columns, may produce incorrect results in SQL Server 2000

Article translations Article translations
Article ID: 888998 - View products that this article applies to.
Bug #: 473085 (SQL Server 8.0)

Expand all | Collapse all

On This Page

Article contents

SUMMARY

This article describes the following about this hotfix release:
  • The issues that are fixed by this hotfix package
  • The prerequisites for installing the hotfix package
  • Whether you must restart your computer after you install the hotfix package
  • Whether the hotfix package is replaced by any other hotfix package
  • Whether you must make any registry changes
  • The files that are contained in the hotfix package

SYMPTOMS

In Microsoft SQL Server 2000 with hotfix build 8.00.0837 or a later version, you may run a query that joins two tables by using an equijoin on a smalldatetime data type column. An equijoin is a join where rows from two tables are combined and added to the result set when there are equal values in the joined columns. If a filter condition with a literal is on one of these columns, the query may return incorrect results. The following query is an example of an affected query:
declare @Date datetime
set @Date = '2005-01-01'

Select t1.c1, t2.c2 
from 
t1 Join t2 on t1.smalldatetime_column = t2.smalldatetime_column
Where t1.smalldatetime_column = @Date
For a list of all publicly released SQL Server 2000 Post-Service Pack 3a hotfixes, see the following article in the Microsoft Knowledge Base:
810185 SQL Server 2000 hotfix update for SQL Server 2000 Service Pack 3 and 3a

CAUSE

This problem occurs because the SQL Server 2000 hotfix build 8.00.0837 optimizes queries to include an implied predicate value whenever possible. Because the implied parameter incorrectly uses a 4-byte smalldatetime constant instead of the 8 byte datetime constant, incorrect evaluation of the comparison occurs at run time.

RESOLUTION

Hotfix information

A supported hotfix is available from Microsoft. However, this hotfix is intended to correct only the problem that is described in this article. Apply this hotfix only to systems that are experiencing this specific problem.

If the hotfix is available for download, there is a "Hotfix download available" section at the top of this Knowledge Base article. If this section does not appear, submit a request to Microsoft Customer Service and Support to obtain the hotfix.

Note If additional issues occur or if any troubleshooting is required, you might have to create a separate service request. The usual support costs will apply to additional support questions and issues that do not qualify for this specific hotfix. For a complete list of Microsoft Customer Service and Support telephone numbers or to create a separate service request, visit the following Microsoft Web site:
http://support.microsoft.com/contactus/?ws=support
Note The "Hotfix download available" form displays the languages for which the hotfix is available. If you do not see your language, it is because a hotfix is not available for that language.

Prerequisites

You must install SQL Server 2000 Service Pack 3. For more informationabout how to obtain SQL Server 2000 Service Pack 3, click the following article number to view the article in the Microsoft Knowledge Base:
290211 How to obtain the latest SQL Server 2000 service pack
Additionally, this hotfix requires that you also have SQL Server 2000 hotfix build 2000.80.977 installed. For more information about SQL Server 2000 Post SP3a hotfix build 2000.80.977, click the following article number to view the article in the Microsoft Knowledge Base:
888007 You receive a "The product does not have a prerequisite update installed" error message when you try to install a SQL Server 2000 post-Service Pack 3 hotfix

Restart information

You have to restart your SQL Server service after you apply this hotfix.

Hotfix file information

This hotfix contains only those files that are required to correct the issues that this article lists. This hotfix may not contain all the files that you must have to fully update a product to the latest build.

The English version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.
   Date         Time   Version        Size       File name
   ----------------------------------------------------------
   02-Nov-2004  06:02  2000.80.985.0    664,128  Autoplt.dll
   02-Nov-2004  06:02  2000.80.985.0     78,400  Console.exe      
   02-Nov-2004  06:02  2000.80.985.0    332,352  Ctasksui.dll
   02-Nov-2004  06:02  2000.80.985.0    315,968  Custtask.dll
   02-Nov-2004  06:02  2000.80.985.0     33,340  Dbmslpcn.dll
   02-Nov-2004  06:02  2000.80.985.0  1,905,216  Dtspkg.dll       
   02-Nov-2004  06:02  2000.80.985.0    528,960  Dtspump.dll
   02-Nov-2004  06:02  2000.80.985.0     41,536  Dtsrun.exe
   02-Nov-2004  06:02  2000.80.985.0  1,557,052  Dtsui.dll
   02-Nov-2004  06:02  2000.80.985.0    639,552  Dtswiz.dll       
   02-Nov-2004  06:02  2000.80.985.0    352,828  Isqlw.exe        
   02-Nov-2004  06:02  2000.80.985.0     82,492  Itwiz.exe        
   02-Nov-2004  06:02  2000.80.985.0     90,692  Msgprox.dll      
   19-May-2004  23:43  8.11.40209.0     209,408  Mssdi98.dll      
   02-Nov-2004  06:02  2000.80.985.0     62,024  Odsole70.dll     
   02-Nov-2004  06:03  2000.80.985.0     25,144  Opends60.dll     
   02-Nov-2004  05:35                    17,576  Opends60.lib
   02-Nov-2004  06:02  2000.80.985.0     57,904  Osql.exe
   02-Nov-2004  06:02  2000.80.985.0    279,104  Pfutil80.dll     
   02-Nov-2004  06:02  2000.80.985.0    143,940  Qrdrsvc.exe      
   02-Nov-2004  06:02  2000.80.985.0    221,768  Replprov.dll     
   02-Nov-2004  06:03  2000.80.985.0    307,784  Replrec.dll      
   02-Nov-2004  06:03  2000.80.985.0    287,304  Rinitcom.dll     
   02-Nov-2004  06:03  2000.80.985.0     78,416  Sdiclnt.dll      
   02-Nov-2004  06:03  2000.80.985.0     66,112  Semmap.dll       
   02-Nov-2004  06:03  2000.80.985.0     57,916  Semnt.dll
   02-Nov-2004  06:03  2000.80.985.0    492,096  Semobj.dll
   02-Nov-2004  06:02  2000.80.985.0     53,832  Snapshot.exe
   02-Nov-2004  06:01  2000.80.985.0     28,672  Sqlagent.dll
   02-Nov-2004  06:02  2000.80.985.0    311,872  Sqlagent.exe
   02-Nov-2004  06:01  2000.80.985.0    168,001  Sqlakw32.dll
   02-Nov-2004  05:05                     4,352  Sqlakw32.lib
   02-Nov-2004  06:03  2000.80.985.0     33,344  Sqlctr80.dll     
   02-Nov-2004  06:03  2000.80.985.0    815,676  Sqldata.dll      
   02-Nov-2004  06:03  2000.80.985.0  4,215,360  Sqldmo.dll       
   02-Nov-2004  06:02                    25,172  Sqldumper.exe    
   02-Nov-2004  06:02  2000.80.985.0    156,224  Sqlmaint.exe     
   02-Nov-2004  06:03  2000.80.985.0    180,792  Sqlmap70.dll     
   02-Nov-2004  06:03  2000.80.985.0    188,992  Sqlmmc.dll
   02-Nov-2004  06:03  2000.80.985.0    401,984  Sqlqry.dll       
   02-Nov-2004  06:03  2000.80.985.0     57,920  Sqlrepss.dll     
   02-Nov-2004  06:03  2000.80.985.0  7,712,849  Sqlservr.exe     
   02-Nov-2004  06:03  2000.80.985.0    590,396  Sqlsort.dll      
   02-Nov-2004  06:03  2000.80.985.0     45,644  Sqlvdi.dll
   02-Nov-2004  06:03  2000.80.985.0    106,588  Sqsrvres.dll
   02-Nov-2004  06:03  2000.80.985.0     33,340  Ssmsgnet.dll     
   02-Nov-2004  06:03  2000.80.985.0     33,340  Ssmslpcn.dll     
   02-Nov-2004  06:03  2000.80.985.0     33,340  Ssmsqlgc.dll     
   02-Nov-2004  06:03  2000.80.985.0     33,340  Ssmssnet.dll     
   02-Nov-2004  06:03  2000.80.985.0     82,492  Ssnetlib.dll
   02-Nov-2004  06:03  2000.80.985.0     25,148  Ssnmpn70.dll
   02-Nov-2004  06:03  2000.80.985.0    123,456  Stardds.dll
   02-Nov-2004  06:03  2000.80.985.0    158,240  Svrnetcn.dll     
   02-Nov-2004  06:02  2000.80.985.0     76,416  Svrnetcn.exe     
   02-Nov-2004  06:03  2000.80.985.0     49,228  Ums.dll          
   02-Nov-2004  06:03  2000.80.985.0     74,304  Xplog70.dll      
   02-Nov-2004  06:03  2000.80.985.0     98,872  Xpweb70.dll      
   17-Nov-2004  18:13                     6,615  Hotfix1.inf
   17-Nov-2004  18:13                     2,471  Hotfix2.inf
   30-Sep-2003  22:34  8.0.21213.0      352,256  Msvcr71.dll      
   30-Sep-2003  22:34  2000.80.796.0     57,904  Osql.exe
   30-Sep-2003  22:34  2000.80.534.0    127,548  Sqdedev.dll      
   30-Sep-2003  22:34  2000.80.194.0    180,290  Sqlunirl.dll     
   02-Nov-2004  05:01  2000.80.985.0    159,813  Replres.rll
   02-Nov-2004  05:28  2000.80.985.0    172,032  Semobj.rll
   02-Nov-2004  04:53  2000.80.985.0     28,672  Sqlevn70.rll
   02-Nov-2004  05:17  2000.80.985.0    479,232  Sqlmmc.rll
Note Because of file dependencies, the most recent hotfix that contains these files may also contain additional files.

WORKAROUND

To work around this issue, use one of the following methods:
  • Use the cast function to cast the datetime column as a smalldate constant.
  • Create a non-clustered index on the smalldatetime column.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to reproduce the behavior

The following Transact-SQL statements on SQL Server 2000 with hotfix build 8.00.0837 and later versions incorrectly return 0 rows:
select @@version
go
 
Create Table t1 (
      c1 SmallDateTime,
      c2 varchar(15)
)
go
 
Create Table t2 (
      c1 smalldatetime,
      c2 Varchar(15)
)
go
 
Insert Into t1 Values ('2004-10-21','abc')
Insert Into t1 Values ('2004-10-21','efg')
 
Insert Into t2 Values ('2004-10-21', 'ddd') 
Insert Into t2 Values ('2004-10-21', 'eee') 
 
 
declare @Date datetime
set @Date = '2004-10-21'
 
Select t1.*, t2.*
from t1 join t2 
On t1.c1 = t2.c1
Where t1.c1 = @Date
go
 
drop table t1
drop table t2
go 
The correct results are the following four rows. These rows are obtained on a computer that is running SQL Server 2000 with hotfix build 8.00.0760, .0818, and builds through build .0836.
c1                                                     c2              c1                                                     c2              
------------------------------------------------------ --------------- ------------------------------------------------------ --------------- 
2004-10-21 00:00:00                                    abc             2004-10-21 00:00:00                                    ddd
2004-10-21 00:00:00                                    abc             2004-10-21 00:00:00                                    eee
2004-10-21 00:00:00                                    efg             2004-10-21 00:00:00                                    ddd
2004-10-21 00:00:00                                    efg             2004-10-21 00:00:00                                    eee
For more information about the naming schema for SQL Server updates, click the following article number to view the article in the Microsoft Knowledge Base:
822499 New naming schema for Microsoft SQL Server software update packages
For more information about the terminology that Microsoft uses when it corrects software after it is released, click the following article number to view the article in the Microsoft Knowledge Base:
824684 Description of the standard terminology that is used to describe Microsoft software updates

Properties

Article ID: 888998 - Last Review: November 2, 2007 - Revision: 1.5
APPLIES TO
  • Microsoft SQL Server 2000 Desktop Engine
  • Microsoft SQL Server 2000 Service Pack 3
  • Microsoft SQL Server 2000 Personal Edition Service Pack 3
  • Microsoft SQL Server 2000 Service Pack 3
  • Microsoft SQL Server 2000 Service Pack 3
Keywords: 
kbautohotfix kbsqlserv2000presp4fix kbbug kbfix kbhotfixserver kbqfe KB888998

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