SelectLayerByAttribute_management not selecting anything

562
2
08-28-2019 06:09 AM
JohnLay
Occasional Contributor

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%'"
0 Kudos
2 Replies
LanceCole
MVP Regular Contributor

John,

Your BLDG_ID attribute, is it text or numeric in the SDE database?  What about the table?

If it is numeric in your SDE database, LIKE with text wildcards will only work on a text value in select by attribute statement.  You can use a CAST statement to change BLDG_ID to a character string then use the LIKE statement with text wildcards such as  "CAST(BLDG_ID AS CHARACTER(10)) LIKE '37019%'".  Make sure to include a large enough character size by changing the "10" to what you need.

JoshuaBixby
MVP Esteemed Contributor

What back-end is your EGDB?

0 Kudos