• I would actually leave the last 3 subqueries. I'd probably move them to the from using the APPLY operator. The reason is that those seem to be unrelated quantities which when joined would give incorrect results.

    This is an untested extract

    SELECT POC.[Prod_ Order No_],

    CASE WHEN POC.Status = 1 Then 'Planned'

    When POC.Status = 2 Then 'Firm Planned'

    When POC.Status = 3 then 'Released' END AS Status,

    ILE.Inventory,

    CL.[Total Rem. Qty.]

    FROM [XXX$Prod_ Order Component] AS POC

    OUTER APPLY (Select SUM(ILE.[Remaining Quantity])

    FROM [XXX$Item Ledger Entry] AS ILE

    WHERE ILE.[Item No_ ] = POC.[Item No_]) AS ILE(Inventory)

    OUTER APPLY (Select SUM(CL.[Remaining Qty_ (Base)])

    FROM [XXX$Prod_ Order Component] AS CL

    WHERE CL.[Item No_] = POC.[Item No_]

    AND CL.Status IN(1,2,3)) AS CL([Total Rem. Qty.])

    WHERE POC.Status IN(1,2,3)

    AND POC.[Prod_ Order No_] <> ''

    AND POC.[Item No_] <> ''

    Order By POC.[Item No_],POC.[Location Code],POC.Status

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2