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 2008 Forums
 Transact-SQL (2008)
 An aggregate may not appear in the set list of an

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2012-09-18 : 15:09:21
my query is

update b set numsent=COUNT(id) from drep d left join #batches b on b.batchnumber=d.batch where b.batchnumber=d.batch

I get an error
An aggregate may not appear in the set list of an UPDATE statement.

how can I change this
I'm trying to update my temporary table with a count from another table

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-18 : 15:13:25
looks like this is what you're after


update b
set numsent= d.cnt
from (select batch,COUNT(id) as cnt from drep group by batch) d
inner join #batches b
on b.batchnumber=d.batch



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

Go to Top of Page
   

- Advertisement -