AnsweredAssumed Answered

How to use SQL queries in arcpy.SelectLayerByAttribute?

Question asked by cesium133 on Feb 8, 2019
Latest reply on Feb 13, 2019 by cesium133

I'm trying to select features from a layer that I know exist. I'm using [SelectLayerByAttribute_management][1] in arcpy.
I have a layer that is properly defined earlier in the code named "tourmaline". I'm trying to query this layer to return all features with value of "Occurrence" in the field STATUS__NEW.

This is what I have:

where = "Status__New = 'Occurrence'"
arcpy.SelectLayerByAttribute_management(tourmaline, "", where)

No features on the map are selected when this code is run.
I've tried variations of the where clause using double quotes and square brackets around field name, but none of them work.

Using ArcMap's Select Layer By Attributes tool to select the same features using the following SQL statement selects the features correctly.

SELECT * FROM tourmaline WHERE:
Status__New = 'Occurrence'

Why is this happening? Why is my SelectLayerByAttribute statement wrong?


[1]: http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/select-layer-by-attribute.htm

Outcomes