This question already has an answer here:
I am working on a simple script tool that selects features from a .shp and creates a new output with only those features. Basically the user specifies(from a drop down list) the county and the preserve and the tool just does a select from a .shp with all the counties and the same for the preserves. I think the problem lies in my syntax, The tool runs without errors but gives me empty outputs. However if I test it without the user input and just put a county name and preserve name in the SQL statement it works which leads me to believe Im not telling the script to use the user input properly. Here is the select part of my script:
#Variables/Arguments
CNTY = "C:\\CRTOOL\\Data\\FL_Counties.shp"
AP = "C:\\CRTOOL\\Data\\FL_AP.shp"
Select_County = arcpy.GetParameterAsText(0)
Select_AP = arcpy.GetParameterAsText(1)
# Select
arcpy.Select_analysis(CNTY, "C:\\CRTOOL\\Data\\Your_County.shp", "\"NAME\" = '%Select_County%' ")
# Select
arcpy.Select_analysis(AP, "C:\\CRTOOL\\Data\\Your_AP.shp", "\"LONG_NAME\" = '%Select_AP%' ")
Here are tool parameters(I have tried them with and without the ' ' in the filter list:
UPDATE: WORKING SCRIPT
#Local Variables/Arguments
CNTY = "C:\\CRTOOL\\Data\\FL_Counties.shp"
AP = "C:\\CRTOOL\\Data\\FL_AP.shp"
Select_County = arcpy.GetParameterAsText(0)
Select_AP = arcpy.GetParameterAsText(1)
where = '"NAME" = ' + "'%s'" %Select_County
whereB = '"LONG_NAME" = ' + "'%s'" %Select_AP
# Process: Select
arcpy.Select_analysis(CNTY, "C:\\CRTOOL\\Data\\Your_County.shp", where)
# Process: Select
arcpy.Select_analysis(AP, "C:\\CRTOOL\\Data\\Your_AP.shp", whereB )