I am trying to set up a tool that allows the user to input a field value, and was thinking SQL expression would be the way to go.

Sample -

#Selects structure by WorkOrderNumber attribute '150506' 
arcpy.SelectLayerByAttribute_management("Structure", "NEW_SELECTION", "WorkOrderNumber = '150506'")

#Appends selected features from Structure to Structure_New (separate data set)
arcpy.Append_management("Structure", "Structure_New")

#Deletes the selected features from Structure 

this process selects features by a work order number and appends the selected features to a separate data set to archive, and then deletes the selected features. This works fine, what I am trying to figure out is how to set this up as a tool for other user to simply input the work order number and run it.

  • Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format.
    – Midavalo
    Commented May 19, 2017 at 19:50
  • 1
    What is your question? Does your Select by Attribute not work? Please edit your question to explain in more detail what you are trying to achieve, and what you've actually tried. Do you have more code that could be added to show what you're doing?
    – Midavalo
    Commented May 19, 2017 at 19:51
  • You need to research arcpy.GetParameterAsText(). Also see Setting parameters in ArcGIS desktop script
    – Midavalo
    Commented May 19, 2017 at 20:26

1 Answer 1


I'm not sure I understand the question, but do you mean something like this?

attribute = arcpy.GetParameterAsText(0) ### Field = '12345'
expression = "Field = " + attribute

arcpy.SelectByAttribute_management("Feature Layer","NEW_SELECTION",expression) 
  • Please don't use your answer to ask a question. If you need more info please leave a comment. A good answer should include information about what your suggested answer does and how to use it. You probably will need to include details of where and how a user can input a value to be used by your arcpy.GetParameterAsText() function, and how to set that up also.
    – Midavalo
    Commented May 19, 2017 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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