I am trying to construct an sql expression using python and afterwards pass it as an input to the arc catalogue select tool. As shown in the following image I am passing a station_ID as a string to my python tool. As shown in the txt document of the image it constructs the sql expression. This expression (where clause), is passed as an argument in the Select tool.

The problem is that Select tool does not realise the input as a where clause, since it returns all rows of my datasource.

enter image description here

How can I correctly construct a where clause or a more complicated query and pass it as an argument to another tool?


In your python script file you should replace output = where with :

arcpy.SetParameter(1, where)

Then in your script tool's properties edit the parameters so that your output where clause parameter has a 'Data Type' equal to SQL Expression and a 'Direction' equal to Output (see image).

Save your .py file and the new script tool properties and remove and re-add the script tool to your model. You should be able to connect the SQL_EXPRESSION output variable to the Select (Analysis) tool.

Also if you want your print statement to appear while the tool is running and in the Results window (for testing or otherwise), consider adding the following line to your python file:

arcpy.AddMessage('The WHERE IS : ' + where)

enter image description here


I think the problem is with what you are setting the output data type as. Here is a model that achieves the same thing as you are doing without the need of a separate python script! The Calculate Value tool is a model only tool which can use python if you need it.

Example model

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.