PC Review


Reply
Thread Tools Rate Thread

Avoiding Null values and using 0 instead

 
 
Frank M.
Guest
Posts: n/a
 
      14th Dec 2003
I have an append query (INSERT INTO) that calculates
totals by subqueries and insert the result into a summary
table. Now, the sub query returns NULL when there are no
records to be summarized. In itself this is fine.
However, in a later update query I use the summary values
in further calculations, and it seems that when you add
values together the result will be NULL if just one of
the values in the expression is NULL, so I need to have a
zero instead of NULL.

I have thought about an extra update query to be run
where NULL values are replaced by 0. If it was just one
field, it would be easy to have an update query where the
criteria would be NULL value in the field. However, I
have quite a lot of summary fields, and having an extra
query for all of them will just make the operation
complicated and increase the probability for errors.

Is there a way to replace NULL in a number of fields in
record in one go, e.g. a conditional assignment of a
value to the field (i.e. if it is NULL set it to 0,
otherwise leave it as it is)?
Or is there any other way to handle the problem?


Regards,

Frank M.
 
Reply With Quote
 
 
 
 
Frank M.
Guest
Posts: n/a
 
      14th Dec 2003
I have found a solution. Using the Nz function to have a
0 returned instead of NULL, e.g.

SumField1 = Nz(EXPRESSION, 0)

Will set SumField1 to zero if the expression calculates
to NULL.

Frank M.


>-----Original Message-----
>I have an append query (INSERT INTO) that calculates
>totals by subqueries and insert the result into a

summary
>table. Now, the sub query returns NULL when there are no
>records to be summarized. In itself this is fine.
>However, in a later update query I use the summary

values
>in further calculations, and it seems that when you add
>values together the result will be NULL if just one of
>the values in the expression is NULL, so I need to have

a
>zero instead of NULL.
>
>I have thought about an extra update query to be run
>where NULL values are replaced by 0. If it was just one
>field, it would be easy to have an update query where

the
>criteria would be NULL value in the field. However, I
>have quite a lot of summary fields, and having an extra
>query for all of them will just make the operation
>complicated and increase the probability for errors.
>
>Is there a way to replace NULL in a number of fields in
>record in one go, e.g. a conditional assignment of a
>value to the field (i.e. if it is NULL set it to 0,
>otherwise leave it as it is)?
>Or is there any other way to handle the problem?
>
>
>Regards,
>
>Frank M.
>.
>

 
Reply With Quote
 
Ken Snell
Guest
Posts: n/a
 
      14th Dec 2003
Check out the Nz function. It allows you to substitute a different value for
a Null in an expression:

For example, the following expression will use 0 as the value of field
FieldName if the value of FieldName is Null:

Answer = 14 + Nz([FieldName], 0)

--
Ken Snell
<MS ACCESS MVP>

"Frank M." <(E-Mail Removed)> wrote in message
news:043201c3c297$0f671550$(E-Mail Removed)...
> I have an append query (INSERT INTO) that calculates
> totals by subqueries and insert the result into a summary
> table. Now, the sub query returns NULL when there are no
> records to be summarized. In itself this is fine.
> However, in a later update query I use the summary values
> in further calculations, and it seems that when you add
> values together the result will be NULL if just one of
> the values in the expression is NULL, so I need to have a
> zero instead of NULL.
>
> I have thought about an extra update query to be run
> where NULL values are replaced by 0. If it was just one
> field, it would be easy to have an update query where the
> criteria would be NULL value in the field. However, I
> have quite a lot of summary fields, and having an extra
> query for all of them will just make the operation
> complicated and increase the probability for errors.
>
> Is there a way to replace NULL in a number of fields in
> record in one go, e.g. a conditional assignment of a
> value to the field (i.e. if it is NULL set it to 0,
> otherwise leave it as it is)?
> Or is there any other way to handle the problem?
>
>
> Regards,
>
> Frank M.



 
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
Display queried records with Null values (null recordcount) Mishanya Microsoft Access Getting Started 6 25th Jan 2009 06:53 PM
update query avoiding null values =?Utf-8?B?RW1tZXR0IEwu?= Microsoft Access Queries 2 13th Jul 2007 04:02 PM
Empty text values aren't null or zero-length, but 2-byte null (\x0000) Mark Steward Microsoft Access 2 21st Jan 2006 02:03 PM
Avoiding Null Values using nz() won't work with Access ODBC driver =?Utf-8?B?Um9i?= Microsoft Access Queries 2 12th Mar 2004 06:01 PM
avoiding Null Values in dataset.table and set them to empty string or 0 Anton Sommer Microsoft ADO .NET 5 27th Aug 2003 12:57 AM


Features
 

Advertising
 

Newsgroups
 


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