select unique and return related table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Microblitz
    New Member
    • Jul 2010
    • 40

    select unique and return related table

    This Code selects a unique entry of the Manufacturing Order.

    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
    I need to use that to select related information from this query.

    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
    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!)
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    I'm not sure I understand your question. Some sample data and results would help.

    Comment

    • Microblitz
      New Member
      • Jul 2010
      • 40

      #3
      I rewrote this and solved it.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Glad you got it fixed. Can you post your solution in case someone else runs into the same situation?

        Comment

        Working...