PC Review


Reply
Thread Tools Rate Thread

counting Null fields

 
 
fishqqq@hotmail.com
Guest
Posts: n/a
 
      24th Aug 2010
i have a query that I'm trying to calculate NULL fields for but am
having problems.

Sold:[sold] (criteria is set to <>NULL)
Unsold:[sold] (criteria is set to IS NULL)
Date:[record date]

i have the same field on the query twice. The idea is the records that
are sold will have a value in them and the records that are unsold
will have no value (null). I'm trying to total both these fields to
show me how many records represent sold and unsold for a particular
date. The "count" option won't count the null records though. is there
a better way to do this?

Tks
STeve
 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      24th Aug 2010
On Tue, 24 Aug 2010 08:18:24 -0700 (PDT), "(E-Mail Removed)"
<(E-Mail Removed)> wrote:

>i have a query that I'm trying to calculate NULL fields for but am
>having problems.
>
>Sold:[sold] (criteria is set to <>NULL)
>Unsold:[sold] (criteria is set to IS NULL)
>Date:[record date]
>
>i have the same field on the query twice. The idea is the records that
>are sold will have a value in them and the records that are unsold
>will have no value (null). I'm trying to total both these fields to
>show me how many records represent sold and unsold for a particular
>date. The "count" option won't count the null records though. is there
>a better way to do this?
>
>Tks
>STeve


A couple of things here: first off, nothing is equal to NULL, nor is anything
*unequal* to NULL. NULL means "undefined, unknown, unspecified" - so any
comparison (=, <>, >, <, etc.) with NULL doesn't return either true or false,
it returns NULL ("I don't know if it's equal or not, because it's undefined!")

Try two calculated fields (in vacant FIELD cells, not in the criteria line)L

Sold:IIF(IsNull([sold]), 0, 1)
Unsold: IIF(IsNull([sold]), 1, 0)

The VBA function IsNull returns either TRUE or FALSE. The IIF will return a 1
or 0 appropriately, and you can use a totals query to sum (not count!) the
1's.
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/For...-US/accessdev/
http://social.answers.microsoft.com/.../en-US/addbuz/
and see also http://www.utteraccess.com
 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      24th Aug 2010
Your criteria for sold should be Is NOT Null . <> Null should fail to return
records.

If you want to count the Nulls then you have to use an expression like

Field: UnSold: IIF([TableName].[Sold] is Null,1,Null)
Total: Count

Field: Sold
Total: Count

You would not apply criteria at all against the field Sold field.

Next time post the SQL of the query you are using and someone can modify it to
give you what you need. Plus it is much easier for us to have the information
on exactly what you are doing in the query.

(Possibly unneeded instructions follow)
Open the query
Select View:Sql from the Menu
Select all the text
Copy it
Paste it into the message

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

(E-Mail Removed) wrote:
> i have a query that I'm trying to calculate NULL fields for but am
> having problems.
>
> Sold:[sold] (criteria is set to <>NULL)
> Unsold:[sold] (criteria is set to IS NULL)
> Date:[record date]
>
> i have the same field on the query twice. The idea is the records that
> are sold will have a value in them and the records that are unsold
> will have no value (null). I'm trying to total both these fields to
> show me how many records represent sold and unsold for a particular
> date. The "count" option won't count the null records though. is there
> a better way to do this?
>
> Tks
> STeve

 
Reply With Quote
 
fishqqq@hotmail.com
Guest
Posts: n/a
 
      24th Aug 2010
On Aug 24, 12:16*pm, John W. Vinson
<jvinson@STOP_SPAM.WysardOfInfo.com> wrote:
> On Tue, 24 Aug 2010 08:18:24 -0700 (PDT), "fish...@hotmail.com"
>
>
>
> <fish...@hotmail.com> wrote:
> >i have a query that I'm trying to calculate NULL fields for but am
> >having problems.

>
> >Sold:[sold] *(criteria is set to <>NULL)
> >Unsold:[sold] (criteria is set to IS NULL)
> >Date:[record date]

>
> >i have the same field on the query twice. The idea is the records that
> >are sold will have a value in them and the records that are unsold
> >will have no value (null). I'm trying to total both these fields to
> >show me how many records represent sold and unsold for a particular
> >date. The "count" option won't count the null records though. is there
> >a better way to do this?

>
> >Tks
> >STeve

>
> A couple of things here: first off, nothing is equal to NULL, nor is anything
> *unequal* to NULL. NULL means "undefined, unknown, unspecified" - so any
> comparison (=, <>, >, <, etc.) with NULL doesn't return either true or false,
> it returns NULL ("I don't know if it's equal or not, because it's undefined!")
>
> Try two calculated fields (in vacant FIELD cells, not in the criteria line)L
>
> Sold:IIF(IsNull([sold]), 0, 1)
> Unsold: IIF(IsNull([sold]), 1, 0)
>
> The VBA function IsNull returns either TRUE or FALSE. The IIF will returna 1
> or 0 appropriately, and you can use a totals query to sum (not count!) the
> 1's.
> --
>
> * * * * * * *John W. Vinson [MVP]
> *Microsoft's replacements for these newsgroups:
> *http://social.msdn.microsoft.com/For...-US/accessdev/
> *http://social.answers.microsoft.com/.../en-US/addbuz/
> *and see alsohttp://www.utteraccess.com


this worked very well thank you
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting Null fields in VBA Magius96 Microsoft Access VBA Modules 3 29th Sep 2008 06:10 PM
Counting fields in the same record only if not null Steve in MN Microsoft Access Forms 0 12th Sep 2008 08:35 AM
Null Group Fields Not Equal to Null Non-Grouped Fields =?Utf-8?B?Q2hlcnlsIExhbW9uZHM=?= Microsoft Access Queries 3 29th Apr 2005 12:22 AM
Counting Null and Not Null values in one query Amy Johnson Microsoft Access Queries 6 20th Nov 2004 05:55 AM
Counting Null Fields John Microsoft Access Queries 2 3rd May 2004 10:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:12 PM.