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.

  • 2
    there's a leading ' in your clause "' PlannedDate = becomes "PlannedDate =. Is RESOLUTION_CODE a string field? if it's numeric it's AND RESOLUTION_CODE = 55 also it's "NEW_SELECTION" not "NEW_SELECTION " the trailing space needs to be removed. You know you can do arcpy.MakeFeatureLayer_management (SOSC, "sosc", Clause) and skip the SelectLayerByAttribute.. – Michael Stimson Apr 16 '15 at 23:07
  • It is a string. – Geoffrey West Apr 16 '15 at 23:08

You have an extra space in your code. And you need to apply the selection to the feature layer you created.


arcpy.SelectLayerByAttribute_management(SOSC, "NEW_SELECTION ", Clause)


arcpy.SelectLayerByAttribute_management("sosc", "NEW_SELECTION", Clause)

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.


The easiest way to do this without demystifying feature layers was to create another feature class and use the where clause there then proceed with the magic of search cursors etc.

SCDE5556= "feature1"
SOSC = "feature2"
Clause1=  "PlannedDate = CONVERT(DATE, GETDATE()) AND RESOLUTION_CODE  IN ( '55', '56')"

Clause2= "NUMBERCYLA > 'SR07885524' AND RESOLUTION_CODE  IN ( '55', '56')"

Copy = "CopyFeature"


    if arcpy.Exists(Copy):

    arcpy.FeatureClassToFeatureClass_conversion(SOSC, "aPath", "aFC", Clause1)

    arcpy.AddField_management(Copy, "DATE", "DATE")

    dateExpression = "Date"

    arcpy.CalculateField_management(Copy, "DATE", dateExpression)

    cursorClause = "DATE = current_date"

    cursor = arcpy.UpdateCursor(Copy, Clause2)
    for row in cursor:
        row.setValue("Prior_RESOLUTION_CODE", row.getValue("RESOLUTION_CODE"))

    fname = "Zero"
    Zero = 0

    arcpy.AddField_management(Copy, "Zero", "TEXT")
    arcpy.CalculateField_management(Copy, fname, Zero)

    cursor = arcpy.UpdateCursor(Copy, Clause2)
    for row in cursor:
        row.setValue("RESOLUTION_CODE", row.getValue("Zero"))

    arcpy.Append_management(Copy, SDE5556, "NO_TEST")

    print "success"

    logger.exception("Something has gone wrong!")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.