0

I've read through most of the other similar questions and nothing so far has addressed my issue; most are about syntax.

I'm trying to select by attribute from a Feature Layer. But every time, Arc announces that it succeeded and nothing is selected. It works just fine using the same expression to select from a Table View. Any ideas?

expression = arcpy.AddFieldDelimiters(tempFeatureLayer, "BLDG_ID") + " LIKE '{0}%'".format(county)

arcpy.SelectLayerByAttribute_management(tempFeatureLayer, "NEW_SELECTION", expression)
if int(arcpy.GetCount_management(tempFeatureLayer)[0]) > 0:
    arcpy.DeleteRows_management(tempFeatureLayer)

It's an SDE Database feature class, if that makes a difference.

I've also tried rewriting the expression as below with the same result:

expression = """ "BLDG_ID" LIKE '37019%'"""

and

expression = "BLDG_ID LIKE '37019%'"
  • It's a text field. – NCFMP Aug 28 at 13:12
  • Try: expression = "{0} LIKE '{1}%'".format(arcpy.AddFieldDelimiters(tempFeatureLayer, "BLDG_ID"), county) – BERA Aug 28 at 13:18
  • Nope. Still selects nothing. If I use this expression on a Table View, however, it will select all the records like it's supposed to. It's only with a Feature Layer that it doesn't work. – NCFMP Aug 28 at 13:31
  • MakeFeatureLayer_management. I've tried UpdateCursor the above is my second attempt to find a way to delete these rows without having to go in SQL Server. The database will not allow UpdateCursor outside of an active Edit session. Staring an edit session crashes Arc. – NCFMP Aug 28 at 13:39
  • 1
    And GetCount etc. of the feature layer is not empty? Maybe you can use ArcSDESQLExecute, I have not tried it. – BERA Aug 28 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.