Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update with aggregate function 1

Status
Not open for further replies.

mlabac

Programmer
Jan 22, 2004
23
US
I need to write an update statement that updates POExtendedTotal grouped by the PONumber with the sum of ItemExtendedCost

I believe I am on the write track as my select statement is returning the right results, but the update statement does not recognize the alias SumOfItemExtendedCost

UPDATE FulfilmentOrders
SET FulfilmentOrders.POExtendedTotal = SumOfItemExtendedCost
From FulfilMentOrders
Where FulfilmentOrders.POnumber IN (SELECT FulfilmentOrders.PONumber, Sum(FulfilmentOrders.ItemExtendedCost) AS sumOfItemExtendedCost
FROM FulfilmentOrders
GROUP BY FulfilmentOrders.PONumber, FulfilmentOrders.Disti_ID, FulfilmentOrders.OrderSent
HAVING FulfilmentOrders.Disti_ID=13 AND FulfilmentOrders.OrderSent=0)


Thoughts?
 
How does this work for you? Good luck!
Code:
UPDATE f
SET f.POExtendedTotal = d.SumOfItemExtendedCost
FROM FulfilMentOrders AS f
    INNER JOIN (
        SELECT PONumber,
            Sum(ItemExtendedCost) AS sumOfItemExtendedCost
        FROM FulfilmentOrders
        WHERE Disti_ID=13
        AND OrderSent=0
        GROUP BY PONumber
     ) AS d
     ON f.POnumber = d.PONumber

--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top