473,395 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to seek a NOT IN RANGE condition

1
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
May 20 '10 #1
1 2460
Delerna
1,134 Expert 1GB
Thats one huge query and to try and unravel that and write it to do what you want, without any data, would be extremely difficult ...... for me at least.

I can give a suggestion however. I hope you can make sense of it.

You need the query to still select the data between YYYY and YYYY as you have stated.

What you need to do is left join the "dochead/docline" combination to oas_element and then select the records where a field from "dochead/docline" is equal to null.

If that field is null then it means there was no matching record in "dochead/docline" between your dates for the record in oas_element , and these are the records you want
The field you choose to test for null does, of course, need to have the proviso that if there was a matching record, then it couldn't be null.
In other words, you can't choose a field that might contain a null value in the table itself.

Does that make sense?


I would suggest that you pull the "dochead/docline" part of your query, along with its date range test, out into it's own query and then reference that query in this one. That should make it a bit easier to get your head around the main query

You can always combine them into one query once you get it working properly.

good luck
May 21 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Dennis D. | last post by:
VB.net does not seem to have adequate structure for handling time within it's own code. Subtract 15 minutes from 00:00 AM, and an out of range condition results. Subtract 15 minutes from 12:00 PM,...
2
by: Colleyville Alan | last post by:
I have been working on an application that queries data from Access, loads it into an array, and then writes it to an Excel spreadsheet. I use the array approach to have fine control over spacing,...
11
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it...
4
by: Jerry | last post by:
I am new to C# and have been trying to figure out how to access a range passed to C#. I have tried everything I can find and have been unable to get it to work. Here is a test sample Ive been...
0
by: Howard Weiss | last post by:
I am writing an application which automates Excel from Managed Visual C++. I have imported the Microsoft Excel Objects COM object per KB 303871 and KB 303872. If I do this in C# or VB, the...
6
by: Greg M | last post by:
I have 5 years of MS Access/VBA development experience and am moving into the VB.net world. I am seeking a tutor which could facilitate this move. I live in Anderson, IN and am willing to...
5
by: saratogajoe | last post by:
For a Medical Chart Audit database, I need to require the user to choose a "From" date and a "To" date
26
by: codercode | last post by:
I'm working on a Visual Basic .NET using Access database. However, my client already have a 30MB database with Sybase ASA and Sybase is way too much for that. Is there anyway I can migrate from a...
3
by: Zoolander | last post by:
Hello, Is it possible to insert a row between 2 existing rows that already have autonumbers? If not is it possible to disengage autonumbers so I can insert rows inbetween existing rows? I am a...
1
by: ph23ms | last post by:
This is going to sound stupid, but I am totally new to Access and need help... I have 3 tables, one I am treating as a Master with Project ID set as the PK. I need 2 other tables to automatically...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.