AnsweredAssumed Answered

Looking for proper syntax for SQL expression in Python to select features by attribute

Question asked by deleted-user-AOHsGDn8SRw7 on Apr 19, 2017
Latest reply on Apr 20, 2017 by bixb0012

I am trying to create a simple code that will select features in a shapefile based on the query {anything within the ATTRIBUTE field that starts with the letter 'P'}. Here the problematic line:


arcpy.SelectLayerByAttribute_management("NJ_Wetlands", "NEW_SELECTION", """"ATTRIBUTE" LIKE P%""")


I know I could do this simply in the toolbox GUI, but I'm trying to learn arcpy. I'm obviously doing something wrong, and it shouldn't be very complicated. I get the error: 


Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\", line 7713, in SelectLayerByAttribute raise e ExecuteError: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute).


I've already tried searching through various forums and some help guides on, but no dice. I guess I need this help to be explained very explicitly, otherwise I am lost.