lucamoiana

Concatenate three number filed in a text ID using Model Builder and Field Calcualtor

Discussion created by lucamoiana on Oct 25, 2013
Latest reply on Oct 25, 2013 by curtvprice
Hi there,

it sound like an easy question, but I couldn???t find my way out.

I have three DOUBLE filed that I want to concatenate in a new TEXT field (UID) using model builder and Field Calculator.

the three DOUBLE filed are ???Cod Istat??? always 5 characters, ID ranging from 1 to 4 characters so I want to add zeros in front of numeric value, and SUB  always 2 characters.

What I came out with is the following code for ???Code block??? but ain???t running



Expression:
concat(ISTAT, ID, SUB)

for ID in concat:
if ID <= 9:
return ISTAT + (???000??? + str(ID)) + SUB
elif ID <= 99:
return ISTAT + (???00??? + str(ID)) + SUB
elif ID <= 999:
return ISTAT + (???0??? + str(ID)) + SUB
else:
return ISTAT + str(ID) + SUB

Outcomes