I would like to write a script where I select a feature class by attributes, add a field for a timestamp, and append the selected features to another feature class. My code is below; Do I need to create a feature layer before selecting by attribute and is it possible to select the layer by attribute, and append the selection another feature class? My code is below;
import arcpy
SDE5556 = "C:\CleanStreets_55_56.gdb\Clean_Streets_55_56"
SOSC = "C:\CleanStreets_55_56.gdb\SOSC"
AppendPath = "C:\CleanStreets_55_56.gdb"
AppendTable = "CleanTable"
aTable = "C:\CleanStreets_55_56.gdb\CleanTable"
Clause= "' PlannedDate = CONVERT(DATE, GETDATE()) AND RESOLUTION_CODE = '55'"
arcpy.MakeFeatureLayer_management (SOSC, "sosc")
arcpy.SelectLayerByAttribute_management(SOSC, "NEW_SELECTION ", Clause)
arcpy.AddField_management(PeterTable, "DATE", "DATE")
dateExpression = "Date"
arcpy.CalculateField_management(aTable, "DATE", dateExpression)
arcpy.Append_management(SOSC, SDE5556, NO_TEST)
When executing the first two lines of the main code block in the Python window in ArcMap I receive Runtime error Traceback (most recent call last): File "<string>", line 14, in <module> File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6688, in SelectLayerByAttribute raise e ExecuteError: ERROR 000800: The value is not a member of NEW_SELECTION | ADD_TO_SELECTION | REMOVE_FROM_SELECTION | SUBSET_SELECTION | SWITCH_SELECTION | CLEAR_SELECTION.
Best Answer
You have an extra space in your code. And you need to apply the selection to the feature layer you created.
Change:
to:
I also foresee problems with you field calculator. And the variable
PeterTable
isn't defined. And you probably want to use your"sosc"
layer as the input for your append I'm guessing.