473,383 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Convert zeros to null

I have a table where, in many fields there are numbers from 0 to 5. I need to convert the zeros into null. I guess I need to create an append query, but I do not know which expression to use so that it will convert the zeros to null.
Thanks for the help!
May 4 '10 #1

✓ answered by gershwyn

If you have a table with the data you want already in it, you should use an update query rather than an append. You can change a single field easily by using a where clause:

Expand|Select|Wrap|Line Numbers
  1. UPDATE [myTable] SET [myField] = Null WHERE [myField] = 0;
It sounds like you have multiple fields though. If you wanted to change multiple fields at the same time, you could use something like this:

Expand|Select|Wrap|Line Numbers
  1. UPDATE [myTable] SET
  2. [myFirstField] = IIF([myFirstField]=0, Null, [myFirstField]),
  3. [mySecondField] = IIF([mySecondField]=0, Null, [mySecondField]),
  4. [myThirdField] = IIF([myThirdField]=0, Null, [myThirdField]);
This would examine the value in each field, setting it to Null if it is zero, and "updating" it to itself (ie, making no changes) it it's not zero.

If you don't have a lot of fields and this is something you only need to do once, you could write and execute the first query several times, once for each fields. (I sometimes do this to make formatting changes with imported data.) The second approach is a little more complex, but can be repeated when necessary.

1 11773
gershwyn
122 100+
If you have a table with the data you want already in it, you should use an update query rather than an append. You can change a single field easily by using a where clause:

Expand|Select|Wrap|Line Numbers
  1. UPDATE [myTable] SET [myField] = Null WHERE [myField] = 0;
It sounds like you have multiple fields though. If you wanted to change multiple fields at the same time, you could use something like this:

Expand|Select|Wrap|Line Numbers
  1. UPDATE [myTable] SET
  2. [myFirstField] = IIF([myFirstField]=0, Null, [myFirstField]),
  3. [mySecondField] = IIF([mySecondField]=0, Null, [mySecondField]),
  4. [myThirdField] = IIF([myThirdField]=0, Null, [myThirdField]);
This would examine the value in each field, setting it to Null if it is zero, and "updating" it to itself (ie, making no changes) it it's not zero.

If you don't have a lot of fields and this is something you only need to do once, you could write and execute the first query several times, once for each fields. (I sometimes do this to make formatting changes with imported data.) The second approach is a little more complex, but can be repeated when necessary.
May 4 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Alex | last post by:
Hi folks, I'm doing calculations based on data in a table, but the data has some zeros in the field I'm dividing by. I'm trying to write a script to replace any field with 0 or null with 1, but...
2
by: T.S.Negi | last post by:
hi, I have data like 0, null or some value in one column. I want to use this column for devision of some other column data. It gives me devision by 0 error. how can I replace all 0 and null...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
1
by: Chris Jackson | last post by:
I'm a novice Access user and am not sure how to solve the following problem. Any help with the following would be greatly appreciated! I have two tables with identical structures, the first holds...
12
by: jkearns | last post by:
Hello, I made a report from a crosstab query following the steps onlined in MSDN's Solutions.mdb example. I now have a dynamic crosstab report (great!), but with one minor problem. I cannot get...
2
by: MDB | last post by:
Hello all, I am not sure if I am using the correct verbiage however, I need to convert  to 02. I believe  is a hex string? And I need to know the into value but I need the 02 value not just 2.
6
by: TN Bella | last post by:
I have a simple text box called txtrefnum, if the user enters a number length less than 9 characters long than I need to have lead zeros added to it. Does anyone know how to do this? I couldn't...
1
by: JongJde | last post by:
Hello, I want to convert different kind of article numbers to one and the same format. For example to 5 characters with zeros in front 12345 => 12345 123 => 00123 1A34 => 01A23 Is...
12
by: aatif | last post by:
I want to convert a string of hex characters (2 hex chars = 1 byte), to ASCII. Hex chars include zeros (0x00) as well, which I want to include in ASCII string. hex string: 5000005355.... ASCII:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.