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
Solved

Returning Total Inventory Quantity from the AdventureWorks Database

Posted on 2006-07-06
2
271 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.net Duplicating a table - primary key not created 3 31
sql, case when & top 1 14 26
Select single row of data for each ID in Select Statement 7 26
SQL R 21 24
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

808 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