Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Update issue

Author  Topic 

crownclit
Starting Member

20 Posts

Posted - 2013-03-04 : 23:42:09
Having dramas with this simple update statement. Could someone please help me out.

Sql:
UPDATE #RC SET #RC.RC11 = (SELECT SUM(#RC11.RC) FROM #RC11 INNER JOIN #RC ON #RC.AgentId = #RC11.AgentId GROUP BY #RC11.AgentId)


Error:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression

Without GroupBy statement runs but updates grand total for all agents instead per individual.

Thanx

CC

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-04 : 23:48:42
[code]
UPDATE rc
SET rc.RC11 = rc11.RCSUM
FROM #RC rc
INNER JOIN (SELECT AgentId ,SUM(RC) AS RCSUM
FROM #RC11
GROUP BY AgentId) rc11
ON rc.AgentId = rc11.AgentId
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

crownclit
Starting Member

20 Posts

Posted - 2013-03-05 : 16:44:18
thank you visakh16 works perfect now :-)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-06 : 01:01:53
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -