Adding a calculated column to a table
Having a problem with adding data to a column based on a calculated result from a second table. I seem to get the same result for all rows. It needs to be either an update or insert statement. It works as a select but that is about it. Here is the code. I need is to add a column to customers which I call Sales that takes the result from Orders and OrderItems table.
-----------------------
SELECT C.CustomerID, SUM(OI.Qty * OI.Price) AS Sales
FROM OrderItems OI
INNER JOIN Orders O
ON OI.InvoiceID = O.InvoiceID
INNER JOIN Customers C
ON O.CustomerID = C.CustomerID
AND O.CustomerID = C.CustomerID
INNER JOIN Products P
ON OI.ProductID = P.ProductID
GROUP BY C.CustomerID, C.CustomerID
Select * from Customers
-------------------------------
|