I'm trying to build a report which highlights the Inactive Suppliers within the ERP database and have the following query which I've built but am struggling to find/apply a "not in range" condition.
SELECT DISTINCT oas_docline.el2 AS [Supplier Code], oas_element.name AS [Supplier Name], oas_element.adddate AS [Date Created], oas_element.moddate AS [Last Modified Date], oas_element.usrname AS [Modified By], oas_element.cur, oas_element.terms AS Terms, IIf([elec]=76,"Yes","") AS [Electronic Payments], IIf([paper]=75,"Yes","") AS [Paper Payments], oas_element.medcode AS [Payment Method], IIf([defbank]=1,"Yes","No") AS [Default Bank], IIf([elec]=76,[bankname],"") AS Bank, IIf([elec]=76,[acname],"") AS [Account Name], IIf([elec]=76,[acref],"") AS [Account Ref], IIf([elec]=76,oas_elmbanklist.sort,"") AS SortCode, IIf([elec]=76,[acnum],"") AS [Account Number]
FROM (((oas_docline INNER JOIN oas_dochead ON (oas_docline.docnum = oas_dochead.docnum) AND (oas_docline.doccode = oas_dochead.doccode) AND (oas_docline.cmpcode = oas_dochead.cmpcode))
INNER JOIN oas_element ON oas_docline.el2 = oas_element.code)
INNER JOIN oas_elmaddrlist ON (oas_element.elmlevel = oas_elmaddrlist.elmlevel) AND (oas_element.code = oas_elmaddrlist.elmcode) AND (oas_element.cmpcode = oas_elmaddrlist.cmpcode))
INNER JOIN oas_elmbanklist ON (oas_element.elmlevel = oas_elmbanklist.elmlevel) AND (oas_element.code = oas_elmbanklist.elmcode) AND (oas_element.cmpcode = oas_elmbanklist.cmpcode)
WHERE (((oas_docline.el2) Like [P%,E%,or %]) AND ((oas_element.adddate) Is Not Null) AND ((oas_element.cmpcode)="MASTER11")
AND ((oas_dochead.yr)>=2008) AND ((oas_dochead.status)<>79)
AND ((oas_element.elmlevel)=2) AND ((oas_element.deldate) Is Null)
AND ((oas_element.matchable)=76)
AND ((oas_element.custsuppacc)=76)
AND ((oas_element.endyear)<=0))
OR (((oas_docline.el2) Like [P%,E%,or %])
AND ((oas_element.adddate) Is Not Null)
AND ((oas_element.cmpcode)="MASTER11")
AND ((oas_dochead.yr)<=2010)
AND ((oas_dochead.status)<>79)
AND ((oas_element.elmlevel)=2)
AND ((oas_element.deldate) Is Null)
AND ((oas_element.matchable)=76)
AND ((oas_element.custsuppacc)=76)
AND ((oas_element.endyear)<=0))
ORDER BY oas_docline.el2, oas_element.medcode DESC;
The above code works for where BETWEEN YYYY and YYYY is specified but I'd like to flip it on it's head and do a NOT IN RANGE query. My concern being that if I simply do a NOT BETWEEN it might bring back data outside that range but some of which may actually exist within the range specified, and I want the results to only bring back el2 codes which exist in oas_element but that aren't used/found in the date range specified on the dochead/docline tables.
Each time I try and specify OUTER JOIN it comes back with either an error indicating "circular reference" or something similar.
Any suggestions would be warmly welcomed!
Many thanks in advance