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")
Solved! Go to Solution.
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.
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.
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")
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)
that worked thanks.