Solved

I need a sql view to return a total from and existing table

Posted on 2013-11-25
2
254 Views
Last Modified: 2013-11-29
I am looking for a query/view to add to a database to retrieve and combine data from an existing table. Table named "Bin" for the purpose of a crystal report. The table consists of 1000's of items, many duplicates in different bins with a different on hand and burn QTY. The results should not duplicate items, should not list any bin but should add the OnHand and burn QTY of duplicate items as TotalQTY

Item Bin      OnHand      Burn      
abc        1           2                 0      
dgf       2           3                 0      
abc       3           4                 3      
abc       4           8            8      
acdf       5           0                 0      
dgf       6           0                 0      
xyz       7           1               1
                        
                        
                        
Query should combine like items and add their onHand and burn colums to return the below results      
                  
Item         TotalQTY                  
abc            25                  
dgf             3                  
acdf             0
xyz          2
0
Comment
Question by:Mcottuli
2 Comments
 
LVL 11

Accepted Solution

by:
Louis01 earned 250 total points
ID: 39676693
select Item, SUM(OnHand + Burn) as TotalQTY                  
  from bin
 group by Item

Open in new window

0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 250 total points
ID: 39676695
Try something like

Select Item, Sum(OnHand) + Sum(Burn) as TotalQty
From TableBin
Group By Item

Open in new window


mlmcc
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now