FIX: User Defined Function Returns Incorrect Result for SELECT Statement with DEFAULT Keyword That References a View (308826)
The information in this article applies to:
- Microsoft SQL Server 2000 (all editions)
This article was previously published under Q308826
BUG #: 353679 (SHILOH_BUGS)
SYMPTOMS
SQL Server 2000 returns incorrect results if you use the DEFAULT keyword with a user defined function (UDF) in a SELECT statement that references a view.
RESOLUTIONTo resolve this problem, obtain the latest service pack for Microsoft 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
To work around this problem, you can force SQL Server to pass the exact value into the SELECT statement instead of using the DEFAULT keyword. To do this, first query the function and store the default value in a temporary variable. Then, you can use the variable to query the UDF while referencing a view. For example, you can use these statements to query the UDF:
declare @tmp sql_variant
select @tmp = dbo.test_udf(default)
select top 1 dbo.test_udf(@tmp) as view_retval from pubs..testauthors
The SELECT statement returns the expected result.
STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.
This problem was first corrected in Microsoft SQL Server 2000 Service Pack 2.
Modification Type: | Major | Last Reviewed: | 10/16/2003 |
---|
Keywords: | kbbug kbfix KB308826 |
---|
|