d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Arcpy/sql Expressions
Add Reply New Topic New Poll
Member
Posts: 29,683
Joined: Sep 7 2006
Gold: 14,543.46
Mar 4 2014 11:34pm
I am stuck on syntax of an sql statement inside CalculateField_management and I can't seem to get the sql expression syntax correct. I can run the select analysis in arcgis and it works but I can't seem to get it to run.
arcpy.CalculateField_management("indata", "field",'!FIELDNAME![2:4]' ,"PYTHON") works fine.
But when I try to do arcpy.CalculateField_management("indata", "field", '!FIELDNAME! = "Value"',"PYTHON")
I get a syntax error on the expression. I've tried multiple options including the three double quotes and various combinations of single and double quotes.

Any ideas?
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Mar 5 2014 09:29am
just a guess:
Code
arcpy.CalculateField_management("indata", "field", "!FIELDNAME! = 'Value'", "PYTHON")
Member
Posts: 29,683
Joined: Sep 7 2006
Gold: 14,543.46
Mar 5 2014 10:24am
Quote (Azrad @ Mar 5 2014 10:29am)
just a guess:
Code
arcpy.CalculateField_management("indata", "field", "!FIELDNAME! = 'Value'", "PYTHON")


I figured it out last night in some late night python epiphany.

arcpy.CalculateField_management("indata", "field", "!FIELDNAME! == \"Value\"","PYTHON")

it was the double equals that threw me off, I had already tried "!FIELDNAME! = \"Value\"".
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll