I'm using ArcMap 10.2. I have 2 columns in a joined table that I need to compare. They need to have the exact same content, and there are about 3,000 rows. I tried this: (changed field names for security)
the Field calculation failed. I think I'm forgetting something really basic in the python script. I would appreciate any advice.
Rather than fiddling around with a script...
1 Add a text/string field to your table... call it ... Check ... or something
2 Select by attribute .... field1 == field2
3 make ... Check... the active field and open the field calculator and type 'yes' with the single quotes around the word
4 from the table, hit the switch selection button to get the reverse
5 from the Check field... type 'no'
you should now have all records filled ...Unless... you have Null values in your fields since a value won't compare to null. If you have any of those, then get back
Thank you! That is a much easier solution!
Just a note: the select by attribute uses SQL and the expression was field 1=field 2. it worked perfectly!
besides what Dan said, always make sure you have a space on both sides of the == at least in your post it looks like the space is missing after the before the ! (which may just be a typo in the post)
When using an if statement, you probably have to use the field calculator code block option. You also mixed up the field name syntax between VB and Python.
def compareCalc(col1, col3): if col1 == col3: return 'yes' else: return 'no'