When I try limiting my results, I limit them too much.
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'
If there is no RepairCode matching ’04 – LS’ I still need the AgrmntID and TotalSaleAmt. Likewise, if there is no AgreementSchedule at all, I need AgrmntID and TotalSaleAmt.
Output:
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
Expected Output:
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
I’ve looked and looked and am now coming here for help. Thank you in advance!!
This is what ended up working:
Thank you very much pkuderov, your response kept pointing me in the right direction. And think you kiwirichard, even though you deleted your response.