Results 1 to 8 of 8
  1. #1
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153

    Question Query to Count records with & without a null value in a date field

    Ok so I have 2 tables.

    1 is called “dbo_kc_alt_tracking” (this table has about 250 records, and is growing) and the 2nd table is called “dbo_av_election” (this table has about 1.2 million records).
    The tables are connected by 2 primary key fields “voter_id” and “election_id”.

    I am trying to do make 2 query’s:
    1. I am trying to put together a query to count the number of records that are in the “dbo_kc_alt_tracking” table that have a “null” value in the field “date_returned” field which is in the “dbo_av_election”.
    2. In addition I want to make the exact same query but I would like it to count the counts that DO have (any) value in the field “date_returned” which is in the “dbo_av_election”.

    Currently when I try to make this (what I thought would be a simple query) it keeps pulling way too many records. I know that since the table “dbo_kc_alt_tracking” only has about 250 records right now the query results should NEVER be higher than that, but it is. Somehow I am counting too many records.


    Can anyone help me with putting this together?

    I attached an image of what I have, but it does not work at all (brings back over 1,000 records which should not happen when i know the table I am trying to pull from has only 250).

    Click image for larger version. 

Name:	Untitled.png 
Views:	22 
Size:	52.2 KB 
ID:	17301
    (the code in the criteria box is just having the records that have the most recent Election id, Every 3 months the election ID gets changed so I only want to pull the most recent records)

    I would like some navigation on how to put this together. Any guidance would be very helpful!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Try a compound linking on the electionID and voterID fields.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153
    Quote Originally Posted by June7 View Post
    Try a compound linking on the electionID and voterID fields.
    What is that? Never heard of it.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Both tables have unique identifier defined by multiple fields. Both involve the voter_id and election_id fields. Need to link on both pairs.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153
    Quote Originally Posted by June7 View Post
    Both tables have unique identifier defined by multiple fields. Both involve the voter_id and election_id fields. Need to link on both pairs.
    So i just need to add another relationship?

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Can establish link in the Relationships window if you want.

    Must establish link between fields in the query builder.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904

  8. #8
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153
    Ok, great I got it working. Thank you!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 02-23-2014, 03:54 PM
  2. Replies: 4
    Last Post: 01-24-2013, 10:10 AM
  3. Replies: 1
    Last Post: 08-31-2012, 01:56 PM
  4. Replies: 1
    Last Post: 02-25-2011, 06:11 PM
  5. use 0 for null value in count query
    By hyperionfall in forum Queries
    Replies: 1
    Last Post: 11-07-2010, 05:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums