473,503 Members | 479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Big problem that shouldn't be

60 New Member
Hi Everyone,

I seem to be having a problem with something that should be quite simple. I have a table (AADT_History) with the following fields:

PCID
AADT
UPDATE_YEAR
OLD_PCID

There can be multiple records for any PCID as it gets a new record added to the table each year. What I am trying to do is to select the most recent record (highest update_year) for each PCID but only where the OLD_PCID field is not null. I have other criteria to further limit the PCIDs to those specific to a certain city (DMA_NUM). The code I'm using is below but I'm finding that it often picks the record with the max Update_Year even though the OLD_PCID is blank. For example I could have a record with an Update_Year of 2007 with the Old_Pcid field populated but my query will return the record with an Update_Year of 2008 even though the Old_Pcid field for this record is blank. I've tried changing the criteria for the old_Pcid to be > 0 in case my field wasn't really blank but that didn't help. Any ideas on what I'm doing wrong?

Expand|Select|Wrap|Line Numbers
  1. SELECT Max(AADT_History.UPDATE_YEAR) AS MaxOfUPDATE_YEAR, First(AADT_History.PCID) AS FirstOfPCID
  2. FROM Counties INNER JOIN (AADT_History INNER JOIN Count_Stations ON AADT_History.PCID = Count_Stations.PCID) ON Counties.CNTY_FIPS = Count_Stations.CNTY_FIPS
  3. WHERE (((Counties.DMA_NUM)=[forms]![login_form]![dma_textbox]) AND ((AADT_History.OLD_PCID) Is Not Null));
  4.  
Mar 6 '09 #1
2 1174
puppydogbuddy
1,923 Recognized Expert Top Contributor
Try this, assuming that [dma_textbox] returns text data type, and that this is code behind a form event procedure.
Expand|Select|Wrap|Line Numbers
  1. If Not IsNull(OLD_PCID) Then
  2.        "SELECT Max(AADT_History.OLD_PCID) AS MaxOfUPDATE_YEAR, First(AADT_History.PCID) AS FirstOfPCID 
  3. FROM Counties INNER JOIN (AADT_History INNER JOIN Count_Stations ON AADT_History.PCID = Count_Stations.PCID) ON Counties.CNTY_FIPS = Count_Stations.CNTY_FIPS 
  4. WHERE (((Counties.DMA_NUM)=[forms]![login_form]![dma_textbox])";  
  5.  
  6. Else 
  7.       "SELECT Max(AADT_History.UPDATE_YEAR) AS MaxOfUPDATE_YEAR, First(AADT_History.PCID) AS FirstOfPCID 
  8. FROM Counties INNER JOIN (AADT_History INNER JOIN Count_Stations ON AADT_History.PCID = Count_Stations.PCID) ON Counties.CNTY_FIPS = Count_Stations.CNTY_FIPS 
  9. WHERE (((Counties.DMA_NUM)=[forms]![login_form]![dma_textbox])";  
  10. End If
  11.  
Mar 8 '09 #2
ramprat
60 New Member
Thanks I'll try it and see if it works.
Mar 9 '09 #3

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

Similar topics

6
3562
by: Tom D. | last post by:
I just got a new computer. I transfered my web site files over and setup my access database system ODBC driver. I've compared settings on both computers. But when I run my web site code on new...
70
2516
by: grün | last post by:
The MSDN techdocs are somewhat limited on this and I wanted more information. Is there any resource that says definitively which is faster /O2 or /Ox and by how much?
12
6876
by: ORC | last post by:
Shouldn't 'ReadFile' block when timeouts are specified even when running in overlapped mode or am I wrong ??? Thanks Ole
4
2737
by: Guadala Harry | last post by:
Is there any way for one Session to remove and update objects in another Session? I seriously doubt it, but thought I'd ask. Here's why: I have some data that is unique per user (or per session -...
34
1800
by: glomde | last post by:
i I would like to extend python so that you could create hiercical tree structures (XML, HTML etc) easier and that resulting code would be more readable than how you write today with packages like...
16
2325
by: cody | last post by:
Shouldn't if (this!=null) generate a compiler warning? in fact, it does not.
10
1753
by: doskey | last post by:
::links not allowed, please read the Posting Guidelines:: The function readit() seems to jump to writeit() when it shouldn't in read.c This has got me stumped. After inside the readit() gets...
8
1694
by: LorenW | last post by:
I am a CSS newbie, but do not understand why Firefox 2.0.0.13 (win) does not honor the margin-bottom in the following code when IE7 and Safari 3.1 do. Shouldn't the two boxes have a vertical space...
12
3030
by: tvnaidu | last post by:
I have Two kinds of web pagess, one is for control page for only admin login, another one is to view status for user login. initially both html files can view with 192.168.0.10/control.htm and other...
0
7203
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
7089
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...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7339
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
7463
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...
0
5581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4678
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...
0
1515
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 ...

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.