This Code selects a unique entry of the Manufacturing Order.
I need to use that to select related information from this query.
Can anyone suggest how I can tack these two pieces of code together without dropping data. Essentially I need to get the data from the second query ONLY if its the first occurance of the Manufacturing order so I can return the correct requested order amount as there are multiple instances of the Manufacturing order table (I know somebody (not me) messed up!)
Code:
DECLARE @suffix NVARCHAR(8) DECLARE @DateStart NVARCHAR(12) DECLARE @DateEnd NVARCHAR(12) SET @suffix = '/M' SET @DateStart = '01/05/2013' SET @DateEnd = '08/05/2013' SELECT a.* from ManufacturingOrders a INNER JOIN (SELECT DISTINCT ManufacturingOrderId FROM ManufacturingOrders) AS b ON a.ManufacturingOrderId = b.ManufacturingOrderId ORDER BY ManufacturingOrderId
Code:
SELECT ManufacturingOrders.QuantityMade AS Quantity_Made, Products.ProductId, Classifications.ClassificationId, Products.ProductDescription,
ManufacturingOrders.QuantityOutstanding AS Outstanding, ManufacturingOrders.DueDate, ManufacturingOrders.ReleaseDate,
ManufacturingOrders.ManufacturingOrderId, Inventory.EffectiveDate, Inventory.CreatedDate, Inventory.LotNumber, Inventory.WorkInProgress,
Inventory.QuantityFilled
FROM ManufacturingOrders INNER JOIN
Products ON ManufacturingOrders.Product = Products.Product INNER JOIN
Classifications ON Products.Classification = Classifications.Classification INNER JOIN
Inventory ON ManufacturingOrders.ManufacturingOrder = Inventory.ManufacturingOrder AND Products.Product = Inventory.Product
WHERE (RIGHT(Products.ProductId, 2) = UPPER(@suffix)) AND (dbo.wfn_GetSimpleDate(Inventory.CreatedDate) BETWEEN @DateStart AND @DateEnd)
ORDER BY Classifications.ClassificationId, ManufacturingOrders.ReleaseDate DESC
Comment