SelectLayerByAttribute_management - Correct syntax for expression

Discussion created by kbennett88 on Mar 22, 2012
Latest reply on Aug 8, 2012 by bruce.nielsen
I'm having some trouble running ArcGIS 10 Python scripting.

I am trying to select the attributes in my layer based on a number of expressions. I don't think I have the Syntax correct. Although, I've followed what is posted here: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000071000000.

This is the portion of my code that is giving me the error.

sel_pts_lyr is a feature layer, and the join I used to generate the data fields was done using env.qualifiedFieldNames = False.

I am running this in gp = arcgisscripting.create(9.3).


  #Select Analysis
  print "Attempting Select"
  expression1 = ' \"ELEV\" <= \"Elev_metre \" + 100 AND \"ELEV\" >= \"Elev_metre\" - 100 '
  expression2 = ' \"SLP\" <= \"mean_slp\"+ \"sd_slp\" AND \"SLP\" >= \"mean_slp\" - \"sd_slp\" '
  expression3 = ' \"ASP\" <= \"mean_asp\" + \"sd_asp\" AND \"ASP\" >= \"mean_asp\" - \"sd_asp\" '

  arcpy.SelectLayerByAttribute_management(sel_pts_lyr, "NEW_SELECTION", expression1)
  arcpy.SelectLayerByAttribute_management(sel_pts_lyr, "SUBSET_SELECTION", expression2)
  arcpy.SelectLayerByAttribute_management(sel_pts_lyr, "SUBSET_SELECTION", expression3)


Traceback (most recent call last):
  File "C:\data2\smart_clip2\model_clip.py", line 91, in <module>
    arcpy.SelectLayerByAttribute_management(sel_pts_lyr, "NEW_SELECTION", expression1)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 4259, in SelectLayerByAttribute
    raise e
ExecuteError: ERROR 000358: Invalid expression
Failed to execute (SelectLayerByAttribute).


Any assistance would be very appreciated!!

Thank you,