I am going through a python script in arcpy 10.1 to Select a field value (i.e. NEAR_DIST) based on three condition as
1) NEAR_DIST<=radius(i.e.500 or anything from user input)
2) NEAR_DIST<>0
3) NEAR_DIST<> -1
I am using 500 which is to be variable asked from user and to be saved in "radius" variable so, i am only using "radius" variable in the SQL statement in following code-
import arcpy,os,sys
feature = "C:\Users\Bakul\Desktop\Od\example_shapefile\Polyline_segments_example.shp"
radius = 500
# create a dictionary to hold the list of near ids for each input id
nearest_dict = dict()
arra = []
whereClause = '''"NEAR_DIST" <= '%{x}%' AND "NEAR_DIST" <>'%{y}%' AND "NEAR_DIST" <>'%{z}%\''''.format(x=radius,y=-1,z=0)
print radius
with arcpy.da.SearchCursor(feature, "NEAR_DIST", whereClause) as rows: ##NEAR_DIST is a field, I need sort all NEAR_DIST <=500 (i.e radius) and not equal 0 and -1
for row in rows:## debugger does not pass here,
nearest_id = row[0]
arra.append(nearest_id)
del rows
del row
print arra
Debugger Error is
500
Traceback (most recent call last):
File "C:\Users\Bakul\Desktop\Od\Python\scratch.py", line 89, in <module>
for row in rows:
RuntimeError: An invalid SQL statement was used.
Can you tell where is the problem (i think in SQL whereClause)?