Results 1 to 5 of 5
  1. #1
    jpvonhemel is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    39

    Count() and Null Values

    Hello,

    I have a simple table that includes a text field with patient complaints (fldRFV). My need is to evaluate the fldRFV field for string includes some key text, IE RASH, LESION, OR SORE, and count each record when true, grouped by the visit date, ie:

    9/1/11 | 5
    9/2/11 | 6


    9/3/11 | 2

    I have progressed to where it mostly works, but my issue is when a fldRFV record does not have any of these responses. The Count() function returns a null value and skips this date in the count. Here is my code:

    Code:
    SELECT tblEDPatients.fldVisitDate, Count([tblEDPatients].[fldRFV]) AS CountEDWRashRFV, "EDWRash" as SurvType
    FROM tblEDPatients
    WHERE (((tblEDPatients.fldRFV) Like "*RASH*" Or (tblEDPatients.fldRFV) Like "*LESION*" Or (tblEDPatients.fldRFV) Like "*SORE*"))
    GROUP BY tblEDPatients.fldVisitDate, tblEDPatients.fldEDLoc
    HAVING (((tblEDPatients.fldEDLoc)="EDW"))
    ORDER BY tblEDPatients.fldVisitDate;


    I have tried including Nz(Count([tblEDPatients].[fldRFV]),0), but it would not place a zero where null records are encountered. I am stuck and would be grateful for some ideas.

    Thank you very much,


    Jerold

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    You are not picking up any null values in your fldRFV so they aren't accounted for. If you want to include all null value reasons add

    or is null

    to the criteria of the fldRFV along with your existing criteria for that field.

  3. #3
    jpvonhemel is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    39
    Rpeare,

    Thanks for reading and responding. Either I don't understand or I wasn't clear in my explanation?

    The field will always have a response in it, so the field will never be null. There will be records where the strings do not match my conditions. It is these times when I want it to output zero when fldRFV strings do contain any of my keywords.

    Thanks,
    Jerold

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    Well again, with your criteria of:

    Like "*RASH*" Or Like "*LESION*" Or Like "*SORE*"

    You are only counting records with these possibilities. If you want to count all records regardless of what type but have a 0 sum if it doesn't mach these criteria you'd have to have something more like:

    Code:
    SELECT tblEDPatients.fldVisitDate, Sum(IIf([fldrfv] Like "*rash*" Or [fldrfv] Like "*lesion*" Or [fldrfv] Like "*sore*",1,0)) AS CountEDWRashRFV, "EDWRash" AS SurvType
    FROM tblEDPatients
    GROUP BY tblEDPatients.fldVisitDate, tblEDPatients.fldEDLoc
    HAVING (((tblEDPatients.fldEDLoc)="EDW"))
    ORDER BY tblEDPatients.fldVisitDate;
    Realistically you should have a table that stores the possible values of RFV with a unique identifier (autonumber is fine) and store the unique key in the fldRFV field. Then in your table that stores the RFV values you can also store a category or categories that would eliminate the need to 'hard code' for specific reason descriptions.

  5. #5
    jpvonhemel is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    39
    @rpeare

    Thank you very much. This looks like it is working and has saved me hours of racking my brain with trial and error. I greatly appreciate your help!

    Jerold

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

Similar Threads

  1. Displaying Count if Null value exists
    By adams.bria in forum Queries
    Replies: 3
    Last Post: 08-31-2011, 11:56 AM
  2. Replies: 1
    Last Post: 02-25-2011, 06:11 PM
  3. null values
    By ippy in forum Queries
    Replies: 3
    Last Post: 12-20-2010, 10:39 AM
  4. use 0 for null value in count query
    By hyperionfall in forum Queries
    Replies: 1
    Last Post: 11-07-2010, 05:12 PM
  5. Fill in Null values
    By Petefured in forum Queries
    Replies: 1
    Last Post: 10-06-2008, 12:54 PM

Tags for this Thread

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