当我试图限制我的结果时,我限制得太多了。
Select Distinct Agreements.AgrmntID, Agreements.Status, JobSites.SiteName,
AgreementCharges.TotalSaleAmt, AgreementCharges.PartID,
AgreementSchedules.FormanEmpID, LaborCodeTypes.RepairCode
From Agreements Inner Join
AgreementCharges On Agreements.AgrmntID = AgreementCharges.AgrmntID Inner Join
JobSites On JobSites.CustSiteID = Agreements.CustSiteID Left Outer Join
AgreementSchedules On Agreements.AgrmntID = AgreementSchedules.AgrmntID
Left Outer Join
LaborCodeTypes On LaborCodeTypes.RepairID = AgreementSchedules.RepairID
Where Agreements.Status = 2 And AgreementCharges.PartID = 31 And
LaborCodeTypes.RepairCode = '04 - LS'
如果没有与“04 - LS”匹配的 RepairCode,我仍然需要 AgrmntID 和 TotalSaleAmt。同样,如果根本没有 AgreementSchedule,我需要 AgrmntID 和 TotalSaleAmt。
输出:
AgrmntID Status SiteName TotalSaleAmt PartID FormanEmpID RepairCode
-------------------------------------------------------------------------
2 2 TEST01 $100.00 31 66 04 - LS
2 2 TEST03 $300.00 31 21 04 - LS
预期输出:
AgrmntID Status SiteName TotalSaleAmt PartID FormanEmpID RepairCode
-------------------------------------------------------------------------
2 2 TEST01 $100.00 31 66 04 - LS
2 2 TEST02 $200.00 31
2 2 TEST03 $300.00 31 21 04 - LS
我看了又看,现在来这里寻求帮助。先感谢您!!