I am running multiple queries one at a time an massaging the data into Excel to create a spreadsheet. I want to be able to execute one query to do all. When I run these together it seems to multiply the quantities on some of the numbers.
My material table has part numbers in it. I want to pull part number, description, and class from the Material table. I have a Material_Location table that has on-hand quantities in it. There may be multiple Material_Location records for a part number or there may be no records. My Sales Order detail has order quantities by part number or it may not have any records because it has no orders for a particular part number. Picked is a quantity field from the Sales Order detail. My Job record is to show the quantities that we are making by part number. There my be multiple Jobs for a part number or no jobs for a part number. I am looking to create an output dataset that shows:
Material Description Class SalesCode OnHand OnOrder Picked JobQty
I am thinking it should have the following:
Select M.Material As [Material]
select M.Material As [Material] ,M.Description As [Description] ,M.Class As [Class] ,M.Sales_Code As [SalesCode] ,Sum(ML.On_Hand_Qty) As [OnHand] ,Sum(SD.Order_Qty) As [OrderQty] ,Sum(SD.Picked_Qty) As [Picked] ,Sum(J.OrderQty) As [JobQty] from [PRODUCTION].dbo.Material As M where M.Status = 'Active' and M.Type = 'F' Left outer join [PRODUCTION[.dbo.Material_Location As ML on M.Material = ML.Material Left outer join [PRODUCTION].dbo.SO_Detail As SD on M.Material = SD.Material and SD.Status = 'Open' Left outer join [PRODUCTION].dbo.Job As J on M.Material = J.Material and J.Status = 'Active'
SWProduction