Hi @ahmed salah ,
We recommend that you post CREATE TABLE statements for your tables together with INSERT statements with sample data, enough to illustrate all angles of the problem. We also need to see the expected result of the sample.
You could also refer below methods and check whether any of them is helpful.
Method 1:
SELECT np.PartNumber, np.CompanyID
FROM parts.nop_part np
INNER JOIN Z2DataCompanyManagement.CompanyManagers.Company c WITH(NOLOCK) ON np.CompanyID = c.CompanyID
WHERE NOT EXISTS
(SELECT 1 FROM parts.chemicalmaster cm LEFT JOIN Parts.ChemicalMissingParts cmp ON cmp.PartID = cm.PartID
WHERE cm.PartID=np.PartID
)
Method 2:
SELECT np.PartNumber, np.CompanyID
FROM parts.nop_part np
INNER JOIN Z2DataCompanyManagement.CompanyManagers.Company c WITH(NOLOCK) ON np.CompanyID = c.CompanyID
WHERE NOT EXISTS
(SELECT 1 FROM parts.chemicalmaster cm
WHERE cm.PartID=np.PartID
)
AND NOT EXISTS
(SELECT 1 FROM Parts.ChemicalMissingParts cmp
WHERE cmp.PartID=np.PartID
)
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.