Link to home
Start Free TrialLog in
Avatar of neal_harmon
neal_harmon

asked on

SUM in an UPDATE help

Am trying to update a temp table with data from a base table

TEMP has LOCATION, QTY

BASE has LOCATION,QTY,(additional Attributes that make location appear more than once)

I want to update my temp location with a sum of the QTY from the base tables

i.e my "wrong" update is like this

UPDATE temp
SET QTY=(SELECT SUM(qty) from BASE)
WHERE temp.location=base.location

Avatar of BrandonGalderisi
BrandonGalderisi
Flag of United States of America image

UPDATE temp
SET QTY=(SELECT SUM(qty) from BASE WHERE temp.location=base.location)

Nearly, try:

UPDATE temp
SET QTY=(SELECT SUM(qty)
                FROM BASE
                WHERE temp.location=base.location)
WHERE temp.location IN (SELECT location
                                         FROM base)
                                       
Avatar of corpuslabs
corpuslabs


I guess the below query might help u,

Update Temp set Qty = (Select Sum(Qty) from Base where Location = Temp.Location)
Avatar of neal_harmon

ASKER

hmmm....getting error     3706: SYNTAX ERROR: EXPECTED SOMETHING BETWEEN '(' AND THE 'SELECT' KEYWORD

usually that's a missing paren or tick.....

i was try to simplify my original question, below is tha actual code - same logic though....


UPDATE seven_day_tables.nh_cvv1
SET a0108=(SELECT SUM(nbr_lines) FROM vbus.acct_v12 WHERE seven_day_tables.nh_cvv1.clac_cd=vbus.acct_v12.clac_cd)
WHERE seven_day_tables.nh_cvv1.clac_cd IN (SELECT clac_cd FROM vbus.acct_v12);
What DB engine?
teradata
ASKER CERTIFIED SOLUTION
Avatar of corpuslabs
corpuslabs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial