Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

Filtragem do SQL Server 2008


Por favor, tente isto:
SELECT      max(dbo.WOO.WOO_LastReportedHrsDate),dbo.PLT.PLT_ItemID, SUM(dbo.PLD.PLD_IssueQty) AS Issued, dbo.WKO.WKO_WorkOrderID, dbo.WKO.WKO_RequiredQty, dbo.WKO.WKO_CompleteQty, 
                      dbo.WKO.WKO_RequiredQty - dbo.WKO.WKO_CompleteQty AS openbalance, dbo.PLT.PLT_QtyPerAssy, 
                      (dbo.WKO.WKO_CompleteQty * dbo.PLT.PLT_QtyPerAssy - SUM(dbo.PLD.PLD_IssueQty)) * - 1 AS WIP, dbo.WKO.WKO_ItemID, dbo.WOO.WOO_StatusCode, 
                      dbo.WOO.WOO_WorkCenterID
FROM         dbo.PLT INNER JOIN
                      dbo.PLD ON dbo.PLT.PLT_RecordID = dbo.PLD.PLD_PLT_RecordID INNER JOIN
                      dbo.WKO ON dbo.PLT.PLT_WorkOrderID = dbo.WKO.WKO_WorkOrderID LEFT OUTER JOIN
                      dbo.WOO ON dbo.PLT.PLT_WorkOrderID = dbo.WOO.WOO_WorkOrderID
WHERE     (dbo.WKO.WKO_StatusCode = N'Released') AND (dbo.PLT.PLT_ItemID = '9005-20-1794')
AND (dbo.WOO.WOO_LastReportedHrsDate IS NOT NULL) AND (dbo.WOO.WOO_StatusCode IS NOT NULL)
GROUP BY dbo.PLT.PLT_ItemID, dbo.WKO.WKO_WorkOrderID, dbo.WKO.WKO_RequiredQty, dbo.WKO.WKO_CompleteQty, dbo.PLT.PLT_QtyPerAssy, dbo.WKO.WKO_ItemID, 
                      dbo.WOO.WOO_StatusCode, dbo.WOO.WOO_WorkCenterID
HAVING      (SUM(dbo.PLD.PLD_IssueQty) = dbo.WKO.WKO_RequiredQty * dbo.PLT.PLT_QtyPerAssy) 
ORDER BY dbo.WKO.WKO_WorkOrderID