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.locatio n
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.locatio
Nearly, try:
UPDATE temp
SET QTY=(SELECT SUM(qty)
FROM BASE
WHERE temp.location=base.locatio n)
WHERE temp.location IN (SELECT location
FROM base)
UPDATE temp
SET QTY=(SELECT SUM(qty)
FROM BASE
WHERE temp.location=base.locatio
WHERE temp.location IN (SELECT location
FROM base)
I guess the below query might help u,
Update Temp set Qty = (Select Sum(Qty) from Base where Location = Temp.Location)
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.c lac_cd=vbu s.acct_v12 .clac_cd)
WHERE seven_day_tables.nh_cvv1.c lac_cd IN (SELECT clac_cd FROM vbus.acct_v12);
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.c
WHERE seven_day_tables.nh_cvv1.c
What DB engine?
ASKER
teradata
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SET QTY=(SELECT SUM(qty) from BASE WHERE temp.location=base.locatio