473,320 Members | 1,914 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,320 software developers and data experts.

Modifying date dependent query in MSAccess 2002

This is a followup to a question I posed last summer.
http://groups.google.com/groups?hl=e...eader.visi.com

I'm developing a weed management database to track our weed management
practices in the eventual hope of using some statistical models on the data
to measure outcome\success. The database contains principally two tables. One
table contains static information such as an weed patch identifier
<weed_id>, species <species>, Location, etc. The second table contains data
that we collect about each patch from year to year such as treatment date
<tdate>, density <cover_class>, treatment <treatment>, etc. The two tables
are linked via the <weed_id> value.

Initally, with the help of the people on this group, I developed a query
that would report the first density record of each weed_id for a given year
specified by the user. A weed patch could be visited multiple times
in a given year, or not visited at all. Since we treat the weeds patches with
herbicide, the only density value of use in tracking density over time
is the first visit, because each sequential visit would yield densities
influenced by the recent herbicide application.

The query ended up looking like this.

PARAMETERS [Which Year?] Long;
SELECT T1.Weed_id, [Static Infestation Data].Species, T1.[Cover Class]
FROM [Static Infestation Data] INNER JOIN Treatment AS T1 ON [Static
Infestation Data].Weed_id = T1.Weed_id
WHERE (((T1.Date) In (SELECT Min(Date)
FROM Treatment As T2
WHERE Year(Date)= [Which Year?]
AND T1.Weed_ID = T2.Weed_ID
GROUP BY Weed_ID)));

The query works great, however, the data does not fit well into our
statistical analysis package because each table produced does not contain
an entry for every weed_id (remember, some patches are not visited at all in
a given year).

This query needs to be modified so that a value is returned for every
weed_id that is present in the static table. What we would like to do,
instead of inserting a null value, is to insert the density value from the
most recent previous year (again, reporting earliest value in that year).

For example: I run a query for 2001. There are no records in the treatment
table matching year 2001 for weed_id 5. Instead, the earliest record of 2000
is reported for weed_id 5 is reported (or perhaps the earliest record for
year 1998 if it has not been visited since then).

I'm not quite sure where to start with this one because I'm no SQL expert.
Any help you would have would be greatly appreciated.

Thanks

Scott
<sm******@visi.com>


Nov 12 '05 #1
0 1297

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

Similar topics

7
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 =...
7
by: Thomas R. Hummel | last post by:
Hello all, I am trying to write a query that compares a member's enrollment period with the products that their group has had during that period (all members belong to a group and the products...
0
by: Phillip Lyles | last post by:
Hi Everybody, I am setting up several users to run the runtime version of msaccess 2002. All the files run fine with the runtime version except one, and when I run it all I get is a blank...
2
by: John | last post by:
I have a query that returns this recordset: Bob, 1/1/2000 Bob, 3/1/2001 Bob, 2/4/2004 Bob, 5/9/2002 I need the query to return this instead: Bob, 2/4/2004 So, it needs to return the most...
2
by: msaccess | last post by:
Dear knowledgeable folks, System: Windows XP and Access 2002. In my participants form, I have the following date fields: EnrollmentDate: the actual date that the participant officially began...
7
by: Andy Davis | last post by:
I have a table of data in Access 2002 which is used as the source table for a mail merge document using Word 2002 on my clients PC. The data is transferred OK but I've noticed that any dates which...
7
by: Jerome | last post by:
Hallo, I know a lot has already been told about date/time fields in a database but still confuses me, specif when dealing with SQLserver(Express). It seems that sqlserver only accepts the date in...
6
chandru8
by: chandru8 | last post by:
hi to all i am using vb6.0 and msaccess 2003 iam inserting date like the query mentioned below strSql = "Insert into table1 values (#" & Date & "# )" the problem is .., for the 1ST date...
3
chandru8
by: chandru8 | last post by:
hi to all i am using vb6.0 and msaccess 2003 iam inserting date like the query mentioned below strSql = "Insert into table1 values (#" & Date & "# )" the problem is .., for the 1ST date...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.