Avatar of TimothyA
TimothyA

asked on 

Access 2010 Update blank fields to zero

Back to basics.


Can any one tell me how to use the a query to update blank fields to zero? I have tried using update query with  ISBLANK, ISNULL, ISEMPTY, and ISMISSING.  They all update all fields to zero.

Timothy
Microsoft Access

Avatar of undefined
Last Comment
Dale Fye
ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

However, if the field is actually a string, and you want to test for NULLs or zero length strings, and replace those with a zero ("0")  then you might try:

UPDATE yourTable SET [SomeField] = "0" WHERE [SomeField] & "" = ""

This syntax appends a zero length string to [SomeField], the result of which will be a zero length string if [SomeField] IS NULL or if [SomeField] = ""
Avatar of TimothyA
TimothyA

ASKER

Thanks for your suggestions.

All fields in questions are numeric.  They came into numeric fields as blank when the data was brought in.

Thanks again.

Timothy
Avatar of TimothyA
TimothyA

ASKER

Simple and worked great.

Thanks

Timothy
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

If you are new at this, the best way to do this is one field at a time, with the syntax mentioned above (first example should do it).  

You can do it more than one at time, but the syntax is significantly different, and there is greater potential for overwriting the data that exists in the other records/fields.
Avatar of TimothyA
TimothyA

ASKER

Fyed,

Thanks for the advise.  I will do it one field at a time.  I was beginning to try more than one but was skittish.

Thanks again.

Timothy
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

I strongly recommend that you always work with a backup copy of your data.

When you do more than one field at a time, you have to construct the SQL so that it won't replace a value in one field that shouldn't.  By using the NZ( ) function you can pass it the value of a field, and if that field is not NULL, then it will return the value that was passed.  If the field IS NULL then the function will return the value you assigned to the 2nd argument in the function (in this case a zero).

The syntax would look like:

UPDATE yourTable
SET  [Field1] = NZ([Field1], 0)
       ,[Field2] = NZ([Field2], 0)
       ,[Field3] = NZ([Field3], 0)

You don't really need a WHERE clause for this because it will actually replace each value in each of the fields, of every row in your table.

If you have a lot of data, you might add a WHERE clause that looks like:

WHERE [Field1] IS NULL OR [Field2] IS NULL or [Field3] IS NULL
Avatar of TimothyA
TimothyA

ASKER

Fyed,

Thanks so much.

You multi-field code works great without the WHERE clause.

The IS Null or ISNUll clause gives the Where clause problems.

Thanks again.

Timothy
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

glad to help.
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo