Where Clause SQL syntax problem - Urgent Please Help

Discussion created by scottaidh on Apr 10, 2013
Latest reply on Apr 16, 2013 by scottaidh

I am running a select layer by attribute and location query on a feature layer of points made from a shapefile.

I have been stuck for hours on the wording of it and would be grateful if some one would tell me how to do it because I have looked and tried many variations to no avail and there are so many suggestions but none seem to fit.

I want the code to be


but I can't get the right syntax in this case beacuse all the components are variables.  Please could anyone offer any suggestions, it's really urgent and preventing me from progressing and I'll be happy to post up the resuts that work.


# import system modules
import arcpy, os, arcpy
from arcpy import env
arcpy.env.overwriteOutput = True

# get user supplied path, layers and fields
path = arcpy.GetParameterAsText(0) # path is H:\working\Findsites.gdb
cities = arcpy.GetParameterAsText(1) # cities Layer is cities Feature Layer cities.shp
citiesL = "citiesL"
crimeField = arcpy.GetParameterAsText(4) # crimeField is fieldname 'CRIME_INDE' SQL expression
crimefieldindex = arcpy.GetParameterAsText(5) # crime index is CRIME_INDE and is a string 0.02
whereClause = "{0} = '{1}'".format(arcpy.AddFieldDelimiters(citiesL, crimeField), crimefieldindex)
universityField = arcpy.GetParameterAsText(6) # universityField is fieldname 'UNIVERSITY' SQL expression
universityfieldindex = arcpy.GetParameterAsText(7) # universityfieldindex is the UNIVERSITY field and is string integer 1
whereClause2 = "{0} = '{1}'".format(arcpy.AddFieldDelimiters(citiesL, universityField), universityfieldindex)
outfile = arcpy.GetParameterAsText(15) # ootput

arcpy.MakeFeatureLayer_management(cities, citiesL)
arcpy.SelectLayerByAttribute_management(citiesL, "SUBSET_SELECTION", '"' + whereClause + " <= " + crimefieldindex + " AND " + whereClause2 + " = " + universityfieldindex'')
arcpy.CopyFeatures_management(citiesL, outfile)