What you will want to do, is actually change the JOIN
clause to match the Sex Code
and State
, but only return the rows that do NOT match.
INSERT INTO Issues
SELECT Eligibility.ID, Eligibility.[Member Id], Eligibility.[Sex Code], Eligibility.State
FROM Eligibility
LEFT JOIN Ref ON
(Eligibility.[Sex Code]=Ref.[Sex Code]) AND (Eligibility.State=Ref.State)
WHERE Ref.[Sex Code] IS NULL
The WHERE Ref.[Sex Code] IS NULL
will filter out the valid rows, and only return the rows that do not meet your JOIN
criteria.