FIX: A user-defined function returns results that are not correct for a query (883415)



The information in this article applies to:

  • Microsoft SQL Server 2000 Developer Edition SP3a
  • Microsoft SQL Server 2000 Standard Edition SP3a
  • Microsoft SQL Server 2000 Enterprise Edition SP3a
  • Microsoft SQL Server 2000 Personal Edition SP3a
  • Microsoft SQL Server 2000 Enterprise Evaluation Edition SP3a
  • Microsoft SQL Server 2000 Workgroup Edition
  • Microsoft SQL Server 2000 Desktop Engine (MSDE) SP3a
  • Microsoft SQL Server 2000 Developer Edition 64 bit
  • Microsoft SQL Server 2000 Enterprise Edition 64-bit

Bug #: 358054 (SQL Server 8.0)
Microsoft distributes SQL Server 2000 fixes as one downloadable file. Because the fixes are cumulative, each new release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2000 fix release.

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.
back to the top

INTRODUCTION

A user-defined function returns results that are not correct for a query if all the following conditions are true:
  • The GROUP BY clause contains two or more references to the same user-defined function.
  • The calls to the user-defined function pass the same first parameter.
  • The user-defined function takes two or more parameters, and the results that the user-defined function returns depend on the value of the secondary parameters.

Important To resolve this problem, you must install this hotfix and turn on trace flag 9056. You can turn on trace flag 9056 by adding -T9056 to the SQL Server command line or by using DBCC TRACEON(9056, -1) from a query connection.

back to the top

RESOLUTION

Service pack information

To resolve this problem, obtain the latest service pack for Microsoft SQL Server 2000. For more information, 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

Hotfix information

Prerequisites

This hotfix requires SQL Server 2000 Service Pack 3 (SP3). For additional information about 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

back to the top

Restart information

You do not have to restart your computer after you apply this hotfix.

back to the top

Registry information

You do not have to update the registry after you apply this hotfix.

back to the top

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 of 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
   ------------------------------------------------------------------------
   22-Jul-2004  15:00  2000.80.962.0     664,128  Autoplt.dll      
   22-Jul-2004  14:59  2000.80.962.0      78,400  Console.exe      
   22-Jul-2004  15:00  2000.80.962.0     315,968  Custtask.dll     
   22-Jul-2004  15:00  2000.80.962.0      33,340  Dbmslpcn.dll     
   08-Apr-2004  12:42                    786,432  Distmdl.ldf
   08-Apr-2004  12:42                  2,359,296  Distmdl.mdf
   10-Oct-2003  09:48                        180  Drop_repl_hotfix.sql
   22-Jul-2004  15:00  2000.80.962.0   1,905,216  Dtspkg.dll       
   22-Jul-2004  15:00  2000.80.962.0     528,960  Dtspump.dll      
   22-Jul-2004  15:00  2000.80.962.0   1,557,052  Dtsui.dll        
   22-Jul-2004  15:00  2000.80.962.0     639,552  Dtswiz.dll       
   10-Oct-2003  09:48                    747,927  Instdist.sql
   10-Oct-2003  09:48                      1,581  Inst_repl_hotfix.sql
   22-Jul-2004  14:59  2000.80.962.0     352,828  Isqlw.exe        
   22-Jul-2004  14:59  2000.80.962.0      82,492  Itwiz.exe        
   22-Jul-2004  15:00  2000.80.962.0      90,692  Msgprox.dll      
   19-May-2004  14:43  8.11.40209.0      209,408  Mssdi98.dll      
   22-Jul-2004  15:00  2000.80.962.0      62,024  Odsole70.dll     
   22-Jul-2004  15:00  2000.80.962.0      25,144  Opends60.dll     
   22-Jul-2004  14:59  2000.80.962.0      57,904  Osql.exe         
   22-Jul-2004  15:00  2000.80.962.0     279,104  Pfutil80.dll     
   10-Oct-2003  09:37                    550,780  Procsyst.sql
   08-Apr-2004  12:42                     12,305  Qfe469315.sql
   08-Apr-2004  12:42                     19,195  Qfe469571.sql
   21-Jul-2004  08:31                  1,105,167  Replmerg.sql
   22-Jul-2004  15:00  2000.80.962.0     221,768  Replprov.dll     
   22-Jul-2004  15:00  2000.80.962.0     307,784  Replrec.dll      
   21-Jul-2004  08:39  2000.80.962.0     159,813  Replres.rll
   10-Oct-2003  09:48                  1,087,150  Replsys.sql
   10-Oct-2003  09:48                    986,603  Repltran.sql
   22-Jul-2004  15:00  2000.80.962.0     287,304  Rinitcom.dll     
   22-Jul-2004  15:00  2000.80.962.0      78,416  Sdiclnt.dll      
   22-Jul-2004  15:00  2000.80.962.0      66,112  Semmap.dll       
   22-Jul-2004  15:00  2000.80.962.0      57,916  Semnt.dll        
   22-Jul-2004  15:00  2000.80.962.0     492,096  Semobj.dll       
   22-Jul-2004  14:12  2000.80.962.0     172,032  Semobj.rll
   22-Jul-2004  14:59  2000.80.962.0      53,832  Snapshot.exe     
   13-Jul-2004  11:59                    117,834  Sp3_serv_uni.sql
   22-Jul-2004  14:59  2000.80.962.0      28,672  Sqlagent.dll     
   22-Jul-2004  14:59  2000.80.962.0     311,872  Sqlagent.exe     
   22-Jul-2004  14:59  2000.80.962.0     168,001  Sqlakw32.dll     
   22-Jul-2004  15:00  2000.80.962.0      33,344  Sqlctr80.dll     
   22-Jul-2004  15:00  2000.80.962.0   4,215,360  Sqldmo.dll       
   22-Jul-2004  14:59                     25,172  Sqldumper.exe    
   21-Jul-2004  08:29  2000.80.962.0      28,672  Sqlevn70.rll
   22-Jul-2004  14:59  2000.80.962.0     156,224  Sqlmaint.exe     
   22-Jul-2004  15:00  2000.80.962.0     180,792  Sqlmap70.dll     
   22-Jul-2004  15:00  2000.80.962.0     188,992  Sqlmmc.dll       
   22-Jul-2004  14:20  2000.80.962.0     479,232  Sqlmmc.rll
   22-Jul-2004  15:00  2000.80.962.0     401,984  Sqlqry.dll       
   22-Jul-2004  15:00  2000.80.962.0      57,920  Sqlrepss.dll     
   22-Jul-2004  15:00  2000.80.962.0   7,581,777  Sqlservr.exe     
   22-Jul-2004  15:00  2000.80.962.0     590,396  Sqlsort.dll      
   22-Jul-2004  15:00  2000.80.962.0      45,644  Sqlvdi.dll       
   22-Jul-2004  15:00  2000.80.962.0     106,588  Sqsrvres.dll     
   22-Jul-2004  15:00  2000.80.962.0      33,340  Ssmslpcn.dll     
   22-Jul-2004  15:00  2000.80.962.0      82,492  Ssnetlib.dll     
   22-Jul-2004  15:00  2000.80.962.0      25,148  Ssnmpn70.dll     
   22-Jul-2004  15:00  2000.80.962.0     123,456  Stardds.dll      
   22-Jul-2004  15:00  2000.80.962.0     158,240  Svrnetcn.dll     
   22-Jul-2004  15:00  2000.80.962.0      76,416  Svrnetcn.exe     
   22-Jul-2004  15:00  2000.80.962.0      49,228  Ums.dll          
   22-Jul-2004  15:00  2000.80.962.0      98,872  Xpweb70.dll      

Note Because of file dependencies, the most recent hotfix or feature that contains these files may also contain additional files.
back to the top
To work around this problem, in the GROUP BY clause, modify the name of the first parameter for each user-defined function so that the value of each first parameter remains unchanged, but the name of each first parameter is different.

To modify the name of the first parameter for each user-defined function, use one of the following examples.
  • If the first parameter is numeric, follow these steps:
    1. Multiply the first parameter of the first user-defined function by 1.
    2. Multiply the first parameter of the second user-defined function by 2, and then divide it by 2.
    3. Continue to modify the first parameter for the remaining user-defined functions in the same way. For example, multiply the first parameter of the third user-defined function by 3.
  • If the first parameter is a string, follow these steps:
    1. Concatenate the first parameter of the first user-defined function with an empty string.

      An empty string is represented by two single quotation mark characters that have no space between them.
    2. Concatenate the first parameter of the second user-defined function with two empty strings.
    3. Continue to concatenate the first parameters of the remaining user-defined functions in the same way. For example, concatenate the first parameter of the third user-defined function with three empty strings.
Notes
  • For the first parameter of each user-defined function that you change in the GROUP BY clause, you must also change the first parameter in the SELECT clause of the corresponding user-defined function.
  • An empty string is represented by two single quotation mark characters, with no space in between.
back to the top

STATUS

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

This problem was first corrected in Microsoft SQL Server 2000 Service Pack 4.

back to the top

MORE INFORMATION

To reproduce this problem, run the following Transact-SQL script:

USE tempdb
GO

SET NOCOUNT ON
GO

DROP TABLE T1
GO
CREATE TABLE T1 (
    c1 int NOT NULL,
    c2 int NOT NULL,
    c3 int NOT NULL
)
GO

INSERT INTO T1 VALUES ( 1, 2, 3 )
GO

DROP FUNCTION dbo.udf1
GO
CREATE FUNCTION dbo.udf1 ( @c1 int,  @c2 int ) RETURNS int
AS
BEGIN
    RETURN ( @c1 + @c2 )
END
GO

PRINT '*** This is correct.'
SELECT
    dbo.udf1( c1, c2 ),
    dbo.udf1( c3, c1 )
FROM T1 GROUP BY
    dbo.udf1( c1, c2 ),
    dbo.udf1( c3, c1 )
GO

PRINT '*** This is incorrect.'
PRINT '*** The value of 2nd column should be 4, not 3.'
SELECT
    dbo.udf1( c1, c2 ),
    dbo.udf1( c1, c3 )
FROM T1 GROUP BY
    dbo.udf1( c1, c2 ),
    dbo.udf1( c1, c3 )
GO
back to the top

REFERENCES

For a list of previous hotfixes, see the "Microsoft SQL Server 2000 Post-Service Pack 3 or Microsoft SQL Server 2000 Post-Service Pack 3a hotfixes" section in the following Microsoft Knowledge Base article:

290211 How to obtain the latest SQL Server 2000 service pack

For additional information about the naming schema for Microsoft 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 additional information about the terminology that Microsoft uses when correcting 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

back to the top

Modification Type:MinorLast Reviewed:6/1/2006
Keywords:kbbug kbfix kbSQLServ2000preSP4fix kbHotfixServer kbQFE KB883415 kbAudDeveloper