I need to run a process on selected records only in a feature class stored in Enterprise geodatabase (SQL Server) that meet a certain condition:

WC = "Status = 'U' AND IN_City = 'Big City' "

But when I run the arcpy command:

arcpy.SelectLayerByAttribute_management(sde_featureclass, "NEW_SELECTION", WC)

Nothing gets selected

If I use the SQL builder in the select by attributes feature in ArcGIS Pro I get several hundred selected records.

What do I need to do in my script that will make a selection on the featureclass using this criteria where I can run a process that will run only on the selected records?

  • 1
    It's hard to tell if there are case issues or space padding, or the default version in the connection has no data. It's not like ArcPy is doing its own selection criteria here -- The result returned by the database is always correct; if it doesn't match your expectation, it's the expectation that's wrong.
    – Vince
    Commented May 29, 2021 at 1:58

1 Answer 1


My guess from your variable name (sde_featureclass) is that you are using an Enterprise Geodatabase and need to use fully qualified field names.

Try looking at your successful run of Select Layer By Attributes in your Results window and right-clicking to Copy As Python Snippet.

That should assist you with what the fully qualified field names need to look like.

  • Thank you as always. The variable name is from a full path, sde_featureclass that is.
    – geoJshaun
    Commented May 29, 2021 at 3:13

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.