Where_Clause= """"GRIDCODE"=6""" arcpy.SelectLayerByAttribute_management ("Quakesim_lyr", "NEW_SELECTION", Where_Clause)
Solved! Go to Solution.
inputVariable = arcpy.GetParameterAsText(0) arcpy.SelectLayerByAttribute_management ("Quakesim_lyr", "NEW_SELECTION", where_clause='"GRIDCODE"={0}'.format(inputVariable))
Of course, it was even more simple than that. The reason it wasn't working is because I chose "String" for my input instead of "SQL statement" Once I changed the parameter it worked perfectly.
Thanks anyway!
I'm trying to make a tool for end users to use in Arc, and I want to make the SQL statement a variable. So far I have this:
Where_Clause= """"GRIDCODE"=6""" yourvar = 6 Where_Clause= arcpy.AddFieldDelimiters(Quakesim_lyr,"GRIDCODE") + " = â??" + yourvar + "â??" # this if GRIDCODE is actually string Where_Clause= arcpy.AddFieldDelimiters(Quakesim_lyr,"GRIDCODE") + " = " yourvar ## this if GRIDCODE is numeric arcpy.SelectLayerByAttribute_management ("Quakesim_lyr", "NEW_SELECTION", Where_Clause)
which works fine in Python, but when I run it as a tool in arc, I'm getting Invalid Statement errors, even though the statement is the same.
Any advice? Bonus points if you can help me with the next step, which would be to replace the '6' with a variable that I could change.