# arcPy SelectLayerByAttribute_Managment SQL Expression issues using wildcard

I have a Layer of Streams called "My_Channels" with the following source

Data Type:  File Geodatabase Feature Class
Database:   C:\Users\user\Documents\ArcGIS\Default.gdb
Feature Class:  My_Channels
Feature Type:   Simple
Geometry Type:  Line
Coordinates have Z values:  No
Coordinates have measures:  No


I Then Copy the layer so I don't destroy it and create "My_Test_Channels"

I'm attempting to use the arcpy.SelectLayerByAttribute_management({layer},{selection},{WHERE})

I'm executing the code populated with the following SQL WHERE CLAUSE

arcpy.SelectLayerByAttribute_management("MY_Test_Channels","NEW_SELECTION","UNIT_NO= 'E%'")


So far I've tried looking at the arcPy Docs for this tool.

I then want to copy the specific selections to a new layer and put that in my Default.gdb file. To be Clear I'm trying to extract Streams starting with the UNIT_NO "E". I have been able to execute the next code which is arcpy.CopyFeatures_management("My_Test_Channels","cropedLayer") The reason I would like to do these types of operations is I'd like to study those specific stream types and currently our layer is setup with all of the streams for our area."E" as their UNIT_NO There are other stream groupings with other letter designations

Am I using the wrong tool to do this since the feature is a line and not necessarily a layer?

Or is it simply that my SQL expression is not formatted correctly?

I've also looked at using Select Analysis Tool but am unsure which is easiest, I plan to do this on other datasets what may be polygons, polylines, lines, points, etc. The current license that I have does not include the Split tool.

• You need to create a Layer with MakeFeatureLayer before running SelectLayerByAttribute. – klewis Aug 18 '16 at 17:32
• The column name needs to be surrounded by double quotes in the expression. Try "\"UNIT_NO\" = 'E%'". – Bjorn Aug 18 '16 at 17:32
• @Bjorn That did the trick But I then try to copy the layer of selected items as a new layer called "cropedLayer" it's copying the entire layer and not just the portions that have Attribute UNIT_NO strating with "E" I thought I was using the proper wild card to obtain only E streams. – Ravenous Aug 18 '16 at 18:11

arcpy.MakeFeatureLayer_management('My_Channels', 'My_Temp_Layer', "\"UNIT_NO\" LIKE 'E%'")

A SQL selection using wild-cards needs to have a LIKE operator, not a =.
Your statement would be "\"UNIT_NO\" LIKE 'E%'"
arcpy.SelectLayerByAttribute_management("MY_Test_Channels", "NEW_SELECTION", "\"UNIT_NO\" LIKE 'E%'")