sql - Error: An aggregate may not appear UPDATE statement -
i trying update column of temp table using following query:
update t set t.consumedquantity = sum(ma.quantity) @temptable t join defaultshopview dsv on dsv.operationid =@opid join myspec ms with(nolock) on ms.workrequest = dsv.workrequest join myactual ma with(nolock) on ma.specid = ms.specid
but getting error:
an aggregate may not appear in set list of update statement.
how update values?
you can use this:
update t set t.consumedquantity = (select sum(ma.quantity) @temptable join defaultshopview dsv on dsv.operationid =@opid join myspec ms with(nolock) on ms.workrequest = dsv.workrequest join myactual ma with(nolock) on ma.specid = ms.specid ) @temptable t join defaultshopview dsv on dsv.operationid =@opid join myspec ms with(nolock) on ms.workrequest = dsv.workrequest join myactual ma with(nolock) on ma.specid = ms.specid