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.nam e AS [Supplier Name], oas_element.add date AS [Date Created], oas_element.mod date AS [Last Modified Date], oas_element.usr name AS [Modified By], oas_element.cur , oas_element.ter ms AS Terms, IIf([elec]=76,"Yes","") AS [Electronic Payments], IIf([paper]=75,"Yes","") AS [Paper Payments], oas_element.med code 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_elmbank list.sort,"") AS SortCode, IIf([elec]=76,[acnum],"") AS [Account Number]
FROM (((oas_docline INNER JOIN oas_dochead ON (oas_docline.do cnum = oas_dochead.doc num) AND (oas_docline.do ccode = oas_dochead.doc code) AND (oas_docline.cm pcode = oas_dochead.cmp code))
INNER JOIN oas_element ON oas_docline.el2 = oas_element.cod e)
INNER JOIN oas_elmaddrlist ON (oas_element.el mlevel = oas_elmaddrlist .elmlevel) AND (oas_element.co de = oas_elmaddrlist .elmcode) AND (oas_element.cm pcode = oas_elmaddrlist .cmpcode))
INNER JOIN oas_elmbanklist ON (oas_element.el mlevel = oas_elmbanklist .elmlevel) AND (oas_element.co de = oas_elmbanklist .elmcode) AND (oas_element.cm pcode = oas_elmbanklist .cmpcode)
WHERE (((oas_docline. el2) Like [P%,E%,or %]) AND ((oas_element.a dddate) Is Not Null) AND ((oas_element.c mpcode)="MASTER 11")
AND ((oas_dochead.y r)>=2008) AND ((oas_dochead.s tatus)<>79)
AND ((oas_element.e lmlevel)=2) AND ((oas_element.d eldate) Is Null)
AND ((oas_element.m atchable)=76)
AND ((oas_element.c ustsuppacc)=76)
AND ((oas_element.e ndyear)<=0))
OR (((oas_docline. el2) Like [P%,E%,or %])
AND ((oas_element.a dddate) Is Not Null)
AND ((oas_element.c mpcode)="MASTER 11")
AND ((oas_dochead.y r)<=2010)
AND ((oas_dochead.s tatus)<>79)
AND ((oas_element.e lmlevel)=2)
AND ((oas_element.d eldate) Is Null)
AND ((oas_element.m atchable)=76)
AND ((oas_element.c ustsuppacc)=76)
AND ((oas_element.e ndyear)<=0))
ORDER BY oas_docline.el2 , oas_element.med code 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
SELECT DISTINCT oas_docline.el2 AS [Supplier Code], oas_element.nam e AS [Supplier Name], oas_element.add date AS [Date Created], oas_element.mod date AS [Last Modified Date], oas_element.usr name AS [Modified By], oas_element.cur , oas_element.ter ms AS Terms, IIf([elec]=76,"Yes","") AS [Electronic Payments], IIf([paper]=75,"Yes","") AS [Paper Payments], oas_element.med code 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_elmbank list.sort,"") AS SortCode, IIf([elec]=76,[acnum],"") AS [Account Number]
FROM (((oas_docline INNER JOIN oas_dochead ON (oas_docline.do cnum = oas_dochead.doc num) AND (oas_docline.do ccode = oas_dochead.doc code) AND (oas_docline.cm pcode = oas_dochead.cmp code))
INNER JOIN oas_element ON oas_docline.el2 = oas_element.cod e)
INNER JOIN oas_elmaddrlist ON (oas_element.el mlevel = oas_elmaddrlist .elmlevel) AND (oas_element.co de = oas_elmaddrlist .elmcode) AND (oas_element.cm pcode = oas_elmaddrlist .cmpcode))
INNER JOIN oas_elmbanklist ON (oas_element.el mlevel = oas_elmbanklist .elmlevel) AND (oas_element.co de = oas_elmbanklist .elmcode) AND (oas_element.cm pcode = oas_elmbanklist .cmpcode)
WHERE (((oas_docline. el2) Like [P%,E%,or %]) AND ((oas_element.a dddate) Is Not Null) AND ((oas_element.c mpcode)="MASTER 11")
AND ((oas_dochead.y r)>=2008) AND ((oas_dochead.s tatus)<>79)
AND ((oas_element.e lmlevel)=2) AND ((oas_element.d eldate) Is Null)
AND ((oas_element.m atchable)=76)
AND ((oas_element.c ustsuppacc)=76)
AND ((oas_element.e ndyear)<=0))
OR (((oas_docline. el2) Like [P%,E%,or %])
AND ((oas_element.a dddate) Is Not Null)
AND ((oas_element.c mpcode)="MASTER 11")
AND ((oas_dochead.y r)<=2010)
AND ((oas_dochead.s tatus)<>79)
AND ((oas_element.e lmlevel)=2)
AND ((oas_element.d eldate) Is Null)
AND ((oas_element.m atchable)=76)
AND ((oas_element.c ustsuppacc)=76)
AND ((oas_element.e ndyear)<=0))
ORDER BY oas_docline.el2 , oas_element.med code 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
Comment