Solved

Returning Total Inventory Quantity from the AdventureWorks Database

Posted on 2006-07-06
2
273 Views
Last Modified: 2008-03-10
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!

0
Comment
Question by:BoggyBayouBoy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 17052435
SELECT s.ProductID, s.UnitPrice, s.unitPriceDiscount, sum(pri.Quantity) as 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
group by s.ProductID, s.UnitPrice, s.unitPriceDiscount, p.Name
0
 
LVL 1

Author Comment

by:BoggyBayouBoy
ID: 17052692
Sweet!
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question