Results 1 to 9 of 9
  1. #1
    BB_Bryan is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Jun 2017
    Posts
    4

    Query to find count of open records


    Hello
    I have a table with 3 fields. Record ID / Date Created / Date Closed. What i am trying to do is count the total open cases at any given date. So essentially I want to know day by day how many cases were in an "Open State"
    Thank you for any suggestions.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    SELECT DateCreated, Count(*) As HowMany
    FROM TableName
    WHERE DateClosed Is Null
    GROUP BY DateCreated
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    BB_Bryan is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Jun 2017
    Posts
    4
    Thank you. Maybe I did not explain it correctly. If if just counted those files where date closed is not null I would get all cases that are open right now. I am looking to go back in time. Example how many cases were open on March 1 2017. So at this point in time (today) many of those files records would be closed.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Ah, try

    SELECT DateCreated, Count(*) As HowMany
    FROM TableName
    WHERE DateClosed Is Null OR DateClosed > #3/1/2017#
    GROUP BY DateCreated
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    BB_Bryan is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Jun 2017
    Posts
    4
    That's great. Now that I am parsing through the data I see there can be multiple close and reopen. How can I account for that? Thanks in advance

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you attach the db with sample data and your expected result?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    BB_Bryan is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Jun 2017
    Posts
    4

    Sample File

    Quote Originally Posted by pbaldy View Post
    Can you attach the db with sample data and your expected result?
    I have a sample file attached. Basically what i am trying to do is say on a day by day basis going back in time how many cases were open on day x or y or z. Thank you
    Attached Files Attached Files

  8. #8
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    There are no duplicate record numbers in your database which you seem to indicate is causing part of your issue, if you have just one record per record_ID the previous answers should have gotten you what you want

    what was your expected result set from the data you submitted?

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You should check your query. For 3/6/2015, I counted 5 records but the query returned a count of 8.
    This is the query from your dB. Notice the date:
    Code:
    SELECT tbl_Data.Date_Created, Count(tbl_Data.Record_ID) AS CountOfRecord_ID
    FROM tbl_Data
    WHERE (((tbl_Data.Date_Closed) Is Null Or (tbl_Data.Date_Closed)>3/#1/1/2017#))
    GROUP BY tbl_Data.Date_Created;
    Changing the SQL to
    Code:
    SELECT tbl_Data.Date_Created, Count(tbl_Data.Record_ID) AS CountOfRecord_ID
    FROM tbl_Data
    WHERE (((tbl_Data.Date_Closed) Is Null Or (tbl_Data.Date_Closed)>#3/1/2017#))
    GROUP BY tbl_Data.Date_Created;
    provides a count of 5 for the created date of 3/6/2015......

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

Similar Threads

  1. Replies: 5
    Last Post: 02-08-2017, 05:52 PM
  2. Replies: 3
    Last Post: 04-30-2015, 11:46 AM
  3. Replies: 4
    Last Post: 03-29-2014, 01:29 AM
  4. Replies: 1
    Last Post: 01-24-2013, 05:50 PM
  5. COUNT Group Count Records COUNT FUNCTION
    By PMCOFFEY in forum Access
    Replies: 9
    Last Post: 11-09-2012, 09:40 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