The solution to this question is not working for me.

My error message:

File "SumAreas.py", line 24, in
arcpy.SelectLayerByAttribute_management(fc, "NEW_SELECTION, '"CLASS_CODE" = "A"')
File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6688, in
SelectLayerByAttribute raise e
ExecuteError: ERROR 000358:
Invalid expression Failed to execute (SelectLayerByAttribute).

Further message in Python Window's side window:

ERROR 000358: Invalid expression
A column was specified that does not exist.

I am trying to select based on a column ("CLASS_CODE") which is of "String" type.

My line 24 (referenced in Error Message above):

arcpy.SelectLayerByAttribute_management(fc, "NEW_SELECTION", '"CLASS_CODE" = "A"')

I can confirm that feature class "fc" definitely has a column called "CLASS_CODE".

So if the column exists, and is spelled correctly, why am I getting this error?

2 Answers 2


The issue is with the value "A" that is seen as a column. To use the string value, you would need to use and escape single quotes.

arcpy.SelectLayerByAttribute_management(fc, "NEW_SELECTION", '"CLASS_CODE" = \'A\'')

Use AddFieldDelimiters:

The field delimiters used in an SQL expression differ depending on the format of the queried data. For instance, file geodatabases and shapefiles use double quotation marks (" "), personal geodatabases use square brackets ([ ]), and enterprise geodatabases don't use field delimiters. The function can take away the guess work in ensuring that the field delimiters used with your SQL expression are the correct ones.

And three quotes:

sql = """{0} = 'A'""".format(arcpy.AddFieldDelimiters(fc, 'CLASS_CODE')
arcpy.SelectLayerByAttribute_management(fc, "NEW_SELECTION", sql)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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