Link to home
Start Free TrialLog in
Avatar of BoggyBayouBoy
BoggyBayouBoy

asked on

Returning Total Inventory Quantity from the AdventureWorks Database

I would like to return a single row which returns the total items in stock for a given productID.

Currently my query is as follows:
SELECT s.SalesOrderID,s.SalesOrderDetailID, s.OrderQty, s.ProductID, s.UnitPrice, s.unitPriceDiscount,
 s.LineTotal, pri.Quantity, p.Name as Name

from Sales.SalesOrderDetail s
            INNER JOIN production.product p
ON p.ProductID = s.ProductID            
inner join production.productInventory pri on pri.ProductID = s.ProductID
where s.SalesOrderID =@SalesOrderID

Because a single productID can exist in multiple locations, this query can return multiple rows - which I don't want.
Experts, How can I SUM the pri.Quantity and return a single row??  Thanks in advance!

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

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
Avatar of BoggyBayouBoy
BoggyBayouBoy

ASKER

Sweet!