Increment fields with null values

972
2
08-02-2016 08:47 AM
Highlighted
New Contributor II

Hello,

I have a question about using python to auto increment numbers. I have a dataset with a range of numbers already defined (ID : 396548 - 410342) and (ID2 : 392988 - 406624). When I merged data I had fields that carried over 'Null' values. I do not want to change the known numbers, just the null values.

Here is a sample of my table, I have 27k fields with 13k numbered and the rest 'null'

IDID2
nullnull
nullnull
396548392988
410342406642

I'm using

rec=0

def autoIncrement():

global rec

pStart = 1 
pInterval = 1

if (rec == 0): 

  rec = pStart 

else: 

  rec += pInterval 

return rec

ID =

autoIncrement()

I've tried chaging 'rec' to the starting number (ID:396548), but it changes all numbers.

Am I using the right option or is there a better one out there

Reply
0 Kudos
2 Replies
Highlighted
MVP Esteemed Contributor

field calculations apply to all OR just a selection in the table... did you try selecting the records/rows that you want to change, then do the field calculation?  You are also going to have to change 'rec' to be the first number that you want changed, otherwise, it will increment from 0

Reply
0 Kudos
Highlighted
New Contributor II

I glossed over that little aspect. thanks for the help. I hate over thinking/looking simple things.

Reply
0 Kudos