I want to use input string in part of the SQL query, and the code has been posted below.
import arcpy
import os
in_features = arcpy.GetParameterAsText(0)
target_county = arcpy.GetParameterAsText(1)
out_path = os.path.dirname(in_features)
out_name= "%s.shp" % target_county
where_clause=""""CNTY_NM" = %s""" % target_county
arcpy.FeatureClassToFeatureClass_conversion(in_features, out_path, out_name, where_clause)
When I run the script, it gives the error.
I don't know what is wrong with the code. Any suggestions?
I am using ArcGIS 10.3.1 Desktop Advanced License.
Answer
In a SQL where clause, single quotes ("FIELD" = 'provided_value'
) are needed around the match string in the where clause. You are missing the single quotes around the provided value. It should be like this:
where_clause="\"CNTY_NM\" = '%s'" % target_county
No comments:
Post a Comment