473,770 Members | 5,299 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date Query using the NOT operator (Access 97)

I am developing a weed management database for the preserve I work on. One
of the queries I'm working on will allow the user to run a query and see which weed
patches have NOT been treated in the current calendar year.

This query involves two tables. The first contains the static information
about the weed patches. The second contains Treatment information. The
tables look something like this

Static Table fields:
Weed_ID (integer)
Species (text)

Treatment Table Fields:
Treatment number (autonumber)
Weed_ID (integer)
Treatment_date (date/time)
Treatment_type (text)

The tables are joined by Weed_ID

The query needs to parse the treatment table and return [static table].weed_id
and [static table].species where there is NO treatment record(s) with
treatment_date values in the current calendar year.

Access 97 seems to handle the NOT operator in a non standard fashion, that or
my syntax is really messed up.

Any help is greatly appreciated.

Scott Morford
Pine Butte Swamp Preserve
Nov 12 '05 #1
3 11067
Scott Morford <sm******@visi. com> wrote in message news:<3f******* *************** @newsreader.vis i.com>...
I am developing a weed management database for the preserve I work on. One
of the queries I'm working on will allow the user to run a query and see which weed
patches have NOT been treated in the current calendar year.

This query involves two tables. The first contains the static information
about the weed patches. The second contains Treatment information. The
tables look something like this

Static Table fields:
Weed_ID (integer)
Species (text)

Treatment Table Fields:
Treatment number (autonumber)
Weed_ID (integer)
Treatment_date (date/time)
Treatment_type (text)

The tables are joined by Weed_ID

The query needs to parse the treatment table and return [static table].weed_id
and [static table].species where there is NO treatment record(s) with
treatment_date values in the current calendar year.


I think NOT is a red herring... you want an outer join.

SELECT ST.Weed_ID, ST.Species
FROM ST LEFT JOIN TT ON ST.WeedID=TT.We edID
WHERE TT.Treatment_da te NOT BETWEEN Date() AND
DateAdd("yyyy", Date(),-1);

or something like that... but you *definitely* need an outer join.
The part I'm not sure of is the exact syntax of the Between clause.

HTH,
Village Idiot
Nov 12 '05 #2
Scott Morford <sm******@visi. com> wrote in message news:<3f******* *************** @newsreader.vis i.com>...
I am developing a weed management database for the preserve I work on. One
of the queries I'm working on will allow the user to run a query and see which weed
patches have NOT been treated in the current calendar year.

This query involves two tables. The first contains the static information
about the weed patches. The second contains Treatment information. The
tables look something like this

Static Table fields:
Weed_ID (integer)
Species (text)

Treatment Table Fields:
Treatment number (autonumber)
Weed_ID (integer)
Treatment_date (date/time)
Treatment_type (text)

The tables are joined by Weed_ID

The query needs to parse the treatment table and return [static table].weed_id
and [static table].species where there is NO treatment record(s) with
treatment_date values in the current calendar year.

Access 97 seems to handle the NOT operator in a non standard fashion, that or
my syntax is really messed up.

Any help is greatly appreciated.

Scott Morford
Pine Butte Swamp Preserve


Scott,]

Her are 2 solutions:

one using a left outer join and a group by clause (a:
SELECT [Static Table].weed_id, [Static Table].species
FROM [Static Table] LEFT JOIN Treatment ON [Static Table].weed_id =
Treatment.weed_ id
WHERE (((Year([treatment_date]))<>Year(Date() ) Or
(Year([treatment_date])) Is Null))
GROUP BY [Static Table].weed_id, [Static Table].species;
and a more elegant one with a subquery:
SELECT [Static Table].weed_id, [Static Table].species
FROM [Static Table]
WHERE ((([Static Table].weed_id) Not In (select [weed_id] from
treatment where year([treatment_date]) = year(date())))) ;
Both are made in the query-editor of Access in QBE mode. In tha last
one the SQL subquery expression 'Not in ...' must be written manually
in the criteria box.

Marc
Nov 12 '05 #3
I would stay away from a NOT IN subquery if possible. a LEFT JOIN is
*much* faster... <borrowing Kent Brockman's 2 cents...>
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
682760
by: vnl | last post by:
I'm trying to run a SQL query but can't find any records when trying to select a certain date. Here's the sql: SELECT field 1, field2, date_and_time, FROM table1 WHERE date_and_time = '01-SEP-02' I'm getting no results. The date_and_time field is formatted like this: 2002-SEP-02 00:01:04
16
7288
by: !TG | last post by:
I have a table with a date field. All I want to do it get all the records with a date before today. I tried the following: "SELECT * FROM StateLicenses Where (Exp < #07/26/2005#) Order By BranchNo,Satellite;" "SELECT * FROM StateLicenses Where (Exp < 07/26/2005) Order By BranchNo,Satellite;" "SELECT * FROM StateLicenses Where (Exp < " & Now() & ") Order By BranchNo,Satellite;" "SELECT * FROM StateLicenses Where (Exp < #" & Now() & "#)...
4
2493
by: Stewart Allen | last post by:
I'm trying to filter a table that has 2 date fields, the first date will always have a value but the second will only occasionally has a value. Each date field also has a corresponding text field to record the record's status. Sample data: *tblTest* Model Parts CDate CStatus RDate RStatus 616 $359.79 03-Nov-03 C
12
2322
by: Joe Stanton | last post by:
Hello Group I have a query that works in Oracle and SQL Server, but fails in Microsoft Access. The query is: SELECT data fromTABLE1 WHERE data>='A&' AND data<'A''' Here is my sample data:
12
6392
by: Steve Elliott | last post by:
I have a query set up to gather together data between two specified dates. Shown in the query column as: Between #24/09/2004# And #01/10/2004# Is it possible to enter several different date ranges, ie between 24/09/2004 and 01/10/2004 together with 05/10/2004 and 07/10/2004 ? If I enter the "Between" criteria on different lines it returns no data.
2
6516
by: Julie Wardlow | last post by:
Help! I am calculating a future date using the DateAdd function in a query (the calculation also involves an IIf statement), and have managed to get this formula to produce the required result. I then want to search through the records and select those with dates (as caluclated above) within a user defined range, and so I am using a parameter query. However, this query returns dates outside of the range and appears to have particular...
4
1889
by: seegoon | last post by:
Hi to all. I am pretty new to this stuff , so forgive me if I am asking the obvious. I am trying to extract some data from an Access database and am having some trouble. The SQL query that I am using (in VB.net) searches for products depending on selected operator and a timespan. The query works fine is my PC's system date setting is mm/dd/yyyy. If I change it to dd/mm/yyyy the query does not return any info.
2
2469
by: x | last post by:
hi i am a pilot by profession. i want to create a database of my logbook using ms access 2002. i am facing a problem regarding the format of time field. when i select "Data/Time" data type for my time field then this format gives the liberty to record times uptill a figure of 59 in different sub-formats, whereas i want the format to be able to record the times like 80:35 or 1:10 or 1138:00. which means that i have these many hours on a...
4
6808
by: SilentThunderer | last post by:
Hey folks, Let me start out by letting you know what I'm working with. I'm building an application in VB 2005 that is basically a userform that employees can use to "Clock in". The form allows the employee to enter their UserID and select "Login" or "Logout" and then click a submit. When the submit button is clicked, I want the application to dum the NT Userename, UserID, status (Login or Logout) and a date/time stamp into an MS Access...
0
9591
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10053
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10001
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3969
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3573
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.