BUG: Update Using Subquery with Aggregate FunctionsID: Q87311
|
BUG# OS/2: 1436 (4.2)
NT: 880 (4.2)
In an update statement, if you use a subquery to set the value of a
column and include one or more aggregate functions with arithmetic
operations, an error occurs complaining that the subquery returns
multiple values, even if it does not.
For example, the following causes error 512:
Update t1 set c2 =(select sum(c)*1
from t2
where t1.c1=t2.c)
Update t1 set c2 =(select sum(c)
from t2
where t1.c1=t2.c)
SQL Server incorrectly handles arithmetic operations in a subquery that returns aggregate results if the subquery updates a table.
One workaround is to move the constant inside the parentheses if the query remains semantically correct. For example, you can rewrite sum(c)*2 as sum(c*2). Otherwise you can break up the query and use intermediate tables to do the updates.
Microsoft has confirmed this to be a problem in SQL Server 4.2 for OS/2 and Microsoft SQL Server versions 4.20, 4.21, and 4.21a. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
Additional query words: Transact-SQL
Keywords : kbprg kbbug4.20 kbbug4.21 kbbug4.21a SSrvServer SSrvWinNT
Version : 4.2 | 4.2 4.21 4.21a
Platform : OS/2 WINDOWS
Issue type :
Last Reviewed: March 16, 1999