Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

How do you update NULL values within a geodatabase table using the ArcGIS Field Calculator (service pack 4) without changing other values to NULL? I've tried the suggestions on this previous question:

How do you test for a NULL string field in the Field Calculator with Python?

When I run the script it changes everything to NULL.

def RemoveNULL(x):
    if x is None:
        return '0'

RemoveNULL(str(!myxField!))

e.g.

before running script

1
23
NULL
5

after running script

NULL
NULL
NULL
NULL

Can you not use python script on mdb table?

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

You logic is wrong. The way it reads now, if not null, then put 0. That explains why null is now set to zero. Because if not null, so it it is null then it equals 0.

Can you post more of the code?

share|improve this answer
    
Sorry I put the wrong statment, I updated my question. –  artwork21 Jul 9 '12 at 16:26
    
You statement still reads, that is x is none (null), then set to 0. Change the 0 value to something else to see what happens. –  Jamie Jul 9 '12 at 16:50
    
Also add an else statement for what to do if it is not null. –  Jamie Jul 9 '12 at 16:51
add comment

Ok, thanks to Jamie here is the working solution:

def RemoveNULL(x):
    if x is None:
        return ''
    elif x == '':
        return '0'
    else: return x

RemoveNULL(str(!myxField!))
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.