BUG: Update Using Subquery with Aggregate FunctionsLast reviewed: April 28, 1997Article ID: Q87311 |
The information in this article applies to:
NT: 880 (4.2) SYMPTOMSIn 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)However, the following query, without the arithmetic operation (*1), runs without error:
Update t1 set c2 =(select sum(c) from t2 where t1.c1=t2.c) CAUSESQL Server incorrectly handles arithmetic operations in a subquery that returns aggregate results if the subquery updates a table.
WORKAROUNDOne 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.
STATUSMicrosoft 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |