Select by Attributes and append

722
4
Jump to solution
04-27-2020 10:35 AM
2Quiker
Occasional Contributor II

I am trying to update a feature class with points that have "Active" in the "Status" field.

I have tried "Status LIKE 'Active%'" &  "\"Status\" LIKE 'Active%'" for the query but no matter what it appends all of the points.

fc2 = "sde\\blah\\UpdatePoints"
arcpy.DeleteFeatures_management(fc2)

#Output = "UpdatePoints1"
CCAP = "sde\\points\\Points1"

arcpy.MakeFeatureLayer_management(CCAP, "CCAP1_lyr")
arcpy.SelectLayerByAttribute_management("CCAP1_lyr", "NEW_SELECTION", "Status LIKE 'Active%'") #"\"Status\" LIKE 'Active%'"

arcpy.Append_management("CCAP1_lyr", "sde\\blah\\UpdatePoints", "NO_TEST")

‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

You could remove the selection all together and apply the query when creating the Feature Layer.  Ex:

fc2 = "sde\\blah\\UpdatePoints"
arcpy.DeleteFeatures_management(fc2)

#Output = "UpdatePoints1"
CCAP = "sde\\points\\Points1"

arcpy.MakeFeatureLayer_management(CCAP, "CCAP1_lyr", "Status LIKE 'Active%'")

arcpy.Append_management("CCAP1_lyr", "sde\\blah\\UpdatePoints", "NO_TEST")

Also, you make want to execute the Make Feature Layer in ArcGIS Pro to make sure the query is correct.  You can then copy the python command from the History tab.

View solution in original post

4 Replies
JakeSkinner
Esri Esteemed Contributor

You could remove the selection all together and apply the query when creating the Feature Layer.  Ex:

fc2 = "sde\\blah\\UpdatePoints"
arcpy.DeleteFeatures_management(fc2)

#Output = "UpdatePoints1"
CCAP = "sde\\points\\Points1"

arcpy.MakeFeatureLayer_management(CCAP, "CCAP1_lyr", "Status LIKE 'Active%'")

arcpy.Append_management("CCAP1_lyr", "sde\\blah\\UpdatePoints", "NO_TEST")

Also, you make want to execute the Make Feature Layer in ArcGIS Pro to make sure the query is correct.  You can then copy the python command from the History tab.

2Quiker
Occasional Contributor II

I wanted to do select multiple values and tried the following but it seems like it just selects "Active" ones.

I need to select "Active" & "Existing",

fc2 = "sde\\blah\\UpdatePoints"
arcpy.DeleteFeatures_management(fc2)

#Output = "UpdatePoints1"
CCAP = "sde\\points\\Points1"

where_clause = "Status IN ('Active%','Existing%')"
arcpy.MakeFeatureLayer_management(CCAP, "CCAP1_lyr", where_clause)

arcpy.Append_management("CCAP1_lyr", "sde\\blah\\UpdatePoints", "NO_TEST")
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I am surprised you aren't getting an error because your SQL syntax is not valid, i.e., text expressions with wildcards are not supported with the IN operator.  Given your level of SQL knowledge, the best approach is chaining together some LIKE statements:

where_clause = "Status LIKE 'Active%' OR Status LIKE 'Existing%'"
arcpy.MakeFeatureLayer_management(CCAP, "CCAP1_lyr", where_clause)

 

2Quiker
Occasional Contributor II

that worked thanks.

0 Kudos