Advertisement

02.01.2008 at 07:27AM PST, ID: 23129723
[x]
Attachment Details

Query with summed join?

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8
I have a query that is giving me issues with regards to getting a running total everytime new inventory is added. I have 2 tables, stock_receiving and stock_items. Stock receiving is where is record is listed when a part is received for a particular contract (division of our company). It referenced by rcv_id. Stock_items is where all of the current quantities are of each part by contract.  Stock items can have the same part listed multiple times based on the number of divisions that use the part and each location that each division warehouses them at.  Example contract A can have stock number 1234 in location 1 and 2 and contract B can have stock 1234 in location 2 and 3. Even though the same part is in location 2 the quanities have to be kept separate as they belong to two different groups. We do this by having 4 entries in stock items: "stock1234 for division A in location 1", "stock1234 for division A in location 2", "stock1234 for division B in location 2",  and "stock1234 for division B in location 3", each with their respective quantities.  When the item is received an entry goes in the stock_receiving table for that receipt and the qty in stock_items is increased based on the location, division and stock_number so we know how much of each part, at each location, each division has.

When we are receiving it is based solely on the division. So if division A wants to receive STK1234 with a QTY of 100 in location 1, I need to show the total qty now available to division 1 from all of their locations in a column on that receiving screen.


Here is what I use to pull the records on the receiving document with id 12357:

SELECT stock_receiving.STOCK_NO, stock_receiving.PART_NO, stock_receiving.QTY, stock_receiving.CONTRACT_ID, stock_receiving.RCV_ID
FROM STOCK_RECEIVING
WHERE stock_receiving.RCV_ID=12357

Here is what I came up with to pull the total qty of stock 8167 for division 331

SELECT sum(stock_items.qty) as totalqty, stock_items.stock_no
FROM STOCK_ITEMS
WHERE stock_no = 'STK8167' and contract_id = '331'
group by stock_no

They both give me the correct results but I can't figure out how to tie them together in a single query to give me the running tally on the receiving screen each time I add an entry.
 
Expert Comment by sujith80:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by Schuchert:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by sujith80:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by Schuchert:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Accepted Solution by dqmq:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by Schuchert:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
20081119-EE-VQP-46 / EE_QW_2_20070628