Results 1 to 4 of 4
  1. #1
    adams.bria is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2010
    Posts
    22

    Displaying Count if Null value exists


    Code:
    Code:
    SELECT stu_assn.DC_ID, stu_assn.Occ_ID, Count(stu_assn.Occ_ID) AS CountOfOcc_ID, Dept_Request.Num_Req, [Num_Req]-[CountOfOcc_ID] AS Num_Needed
    FROM ((stu_assn INNER JOIN Dept_Cont ON stu_assn.DC_ID = Dept_Cont.DC_ID) INNER JOIN Local_Vars ON Dept_Cont.Aid_Year = Local_Vars.Aid_Year) INNER JOIN Dept_Request ON Dept_Cont.DC_ID = Dept_Request.DC_ID
    WHERE (((Dept_Request.Occ_ID)=[stu_assn].[occ_ID]) AND ((Dept_Cont.aid_year)=[local_vars].[aid_year]))
    GROUP BY stu_assn.DC_ID, stu_assn.Occ_ID, Dept_Request.Num_Req;
    So what I want to happen is even if CountOfOcc_ID is null, if an entry exists for dept_Request.Num_Req I want it to show 0 for the countofocc_ID and display in the query.

    Any ideas?

  2. #2
    gopherking is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    71
    Not sure if you can do this in a Query, but rather than Count(stu_assn.Occ_ID), can you use Nz(Count(stu_assn.Occ_ID),0)?

    This should return a "0" when the Count = Null. Worth a shot ...

  3. #3
    adams.bria is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2010
    Posts
    22
    That unfortunetly did not work. Anyone else got an idea?

  4. #4
    gopherking is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2011
    Posts
    71
    adams.bria,

    I was able to find a location where I was able to use the Nz([field],0) in a query. I am using it on a sum field, which is summed in another query and the Nz([field],0) is applied to the resulting field from that query. So, to get around this issue, if you can create a query that does your Count for you, then in the above query, if you reference the already Counted field in the new query, the Nz([field],0) should work as expected.

    It's a little out of the way, but it should get you what you need.

    gopherking

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

Similar Threads

  1. Replies: 1
    Last Post: 02-25-2011, 06:11 PM
  2. Not Exists Between Query
    By Pells in forum Queries
    Replies: 5
    Last Post: 11-08-2010, 06:13 AM
  3. use 0 for null value in count query
    By hyperionfall in forum Queries
    Replies: 1
    Last Post: 11-07-2010, 05:12 PM
  4. Displaying a null value as 0
    By jordanturner in forum Access
    Replies: 2
    Last Post: 09-17-2010, 09:22 AM
  5. How to use if not exists in access?
    By halifaxdalRaymondXie in forum Queries
    Replies: 1
    Last Post: 01-14-2010, 03:18 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