In my last post I had an issue where I wanted to create multiple shapefiles based on only one attribute field (years). How to do it was answered in that post. I want to make that tool more dynamic so that the user can select any field and any value and make a shapefile for it. Any suggestions on how to use the tool dynamic so that fields and the operator(<,<=,=,>,>=) can also be defined by the user itself.
I tried the following:
import arcpy
fc = arcpy.GetParameterAsText(0)
yrs = arcpy.GetParameterAsText(1)
yrs = yrs.split(';')
subtract = ''
for yr in yrs:
where = '"arcpy.GetParameterAsText(3)" arcpy.GetParameterAsText(2) ' + str(yr) + subtract
subtract = ' AND "arcpy.GetParameterAsText(3)" > ' + str(yr)
filename = str(arcpy.GetParameterAsText(3)) + '.shp'
arcpy.FeatureClassToFeatureClass_conversion(fc, "arcpy.GetParameterAsText(4)", filename, where)
del yr
I get the following error message: : ERROR 999999: Error executing function. An invalid SQL statement was used. An invalid SQL statement was used. Failed to execute (FeatureClassToFeatureClass).
Also attaching the screenshot for properties while adding the script.



– elrobis Dec 12 '12 at 15:49ogr2ogr NewFile.shp Template.shp -where "FID < 0"Year <= 1990;1995doesn't make much sense. Perhaps you could add theINoperator and build a WHERE clause likeYEAR IN(1990, 1995), which basically expands toYEAR = 1990 OR YEAR = 1995, up to how ever many elements within theINstatement. I have an example of how to do that here: http://gis.stackexchange.com/questions/21760/extract-by-attribute-using-modelbuilder-with-user-input/21777#21777 – blah238 Dec 13 '12 at 04:38