<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SQL where caluse syntax Please Help in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/sql-where-caluse-syntax-please-help/m-p/167593#M12942</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Scott,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Add the 'arcpy.AddMessage' function to your script to print out your where clauses:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.AddMessage(whereClause)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, what type of data are you working with? (i.e. shapefiles, File Geodatabase feature classes, Personal Geodatabase feature classes)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 12 Apr 2013 09:39:37 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2013-04-12T09:39:37Z</dc:date>
    <item>
      <title>SQL where caluse syntax Please Help</title>
      <link>https://community.esri.com/t5/python-questions/sql-where-caluse-syntax-please-help/m-p/167590#M12939</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure if I have to post again but older things just seem to get ignored.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please can someone tell me how to write the where clause for&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"CRIME_INDE" &amp;lt;= 0.02 AND "UNIVERSITY" = 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;when everthing is a variable.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have posted my code below.&amp;nbsp; Please ignore the other lines, they all work.&amp;nbsp; The workspaces, paths etc. are user input and are not shown, dont worry - they work.&amp;nbsp; You'll notice several lines of code for the whereclause preceded by # thats because I've tried them and they dont' work. The ONLY part that does not work is the where clauses for SelectLayerByAttribute.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any suggestions are greatly appreciated so please help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Scottaidh&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# import system modules&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy, os, arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.overwriteOutput = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# get user supplied path, layers and fields&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;path = arcpy.GetParameterAsText(0) # path is H:\working\Findsites.gdb&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cities = arcpy.GetParameterAsText(1) # cities Layer is cities Feature Layer cities.shp&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;citiesL = "citiesL"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;counties = arcpy.GetParameterAsText(2) # counties Layer is counties Feature Layer counties.shp&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;countiesL ="countiesL"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;interstates = arcpy.GetParameterAsText(3) # interstates Layer is Feature Layer interstates.shp&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;crimeField = arcpy.GetParameterAsText(4) # crimeField is fieldname 'CRIME_INDE' SQL expression&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;crimefieldindex = arcpy.GetParameterAsText(5) # crime index is CRIME_INDE and is a string 0.02&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#whereClause = '"' + crimeField + '" &amp;lt;= " + crimefieldindex'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#whereClause = '"' + crimeField + '" &amp;lt;= ' + "'" + crimefieldindex + "'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;whereClause = "\"%s\" = '%s'" % (crimeField, crimefieldindex)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;universityField = arcpy.GetParameterAsText(6) # universityField is fieldname 'UNIVERSITY' SQL expression&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;universityfieldindex = arcpy.GetParameterAsText(7) # universityfieldindex is the UNIVERSITY field and is string integer 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#whereClause2 = "'"' + universityField + '" &amp;lt;=' + universityindex"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#whereClause2 = '"' + universityField + '" &amp;lt;= ' + "'" + universityfieldindex + "'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;whereClause2 = "\"%s\" = '%s'" % (universityField, universityfieldindex)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;workforceField = arcpy.GetParameterAsText(8) # workforceField is fieldname 'AGE_18_64' SQL expression&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;workforceindex = arcpy.GetParameterAsText(9) # workforce index is attribute of AGE_18_64 field and is a Double and is 25000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#whereClause3 = "'"' + workforceField + '" &amp;gt;=' + workforceindex"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#whereClause3 = '"' + workforceField + '" &amp;gt;= ' + "'" + workforceindex + "'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;whereClause3 = "\"%s\" = '%s'" % (workforceField, workforceindex)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;farmField = arcpy.GetParameterAsText(10) # farmField is fieldname 'NO_FARMS87' SQL expression&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;farmfieldindex = arcpy.GetParameterAsText(11) # farmfieldindex is the NO_FARMS87 field and is Double integer is 500&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#whereClause4 = "'"' +farmField + '" &amp;gt;=' + farmfieldindex"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#whereClause4 = '"' + farmField + '" &amp;gt;= ' + "'" + farmfieldindex + "'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;whereClause = "\"%s\" = '%s'" % (farmField, farmfieldindex)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;maxKmInterstate = arcpy.GetParameterAsText(12) # interstate WITHIN_A_DISTANCE linear unit&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;nearestInterstate = arcpy.GetParameterAsText(13) # Near Table Analysis table generated&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;targetFeatures = "cityListL" # cities spatial join layer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;joinFeatures = "countiesL" # counties spatial join layer &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cityListFC = arcpy.GetParameterAsText(14) # narrowed down cities list temporary&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cityListL = "CityListL" # the feature layer of the generated cityList feature class&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outputLayer = arcpy.GetParameterAsText(15) # ootput&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#altwhereclause1 = "CRIME_INDE &amp;lt;= 0.02"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#altwhereclause2 = "UNIVERSITY = 1"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#altwhereclause3 = "AGE_18_64 &amp;gt;= 25000"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#altwhereclause4 = "NO_FARMS87 = 500"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# make a layer from the cities feature class&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.MakeFeatureLayer_management(cities, citiesL)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# select layer by location to interstates&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByLocation_management(citiesL, "WITHIN_A_DISTANCE", interstates, maxKmInterstate, "NEW_SELECTION")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Here is the ESRi suggested code for select layer by attribute where clause - doesn't work though&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# whereClause = '"' + crimeField + '" &amp;lt;=' + "'" + crimefieldindex + "'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# arcpy.SelectLayerByAttribute_management(citiesL, "NEW_SELECTION", whereClause + "AND" + whereClause2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# stack exchange suggestion - whereClause = '"' + PipelineIDField + '" = ' + "'" + fullRouteName + "'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# from selection above select layer by attribute select "CRIME_IND" &amp;lt;= 0.02 AND "UNIVERSITY" = 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management(citiesL, "NEW_SELECTION", whereClause + "AND" + whereClause2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# make counties feature layer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.MakeFeatureLayer_management(counties,countiesL)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# select workforce and number of farms&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# new selection on counties layer countiesL&amp;nbsp; "AGE_18_64" &amp;gt;= 25000 AND "NO_FARMS87" &amp;gt;= 500")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management(countiesL, "NEW_SELECTION", whereClause3 + "AND" + whereClause4)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# from selection above select cities intersecting counties&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByLocation_management(citiesL, "INTERSECT", countiesL, "", "SUBSET_SELECTION")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# save selected features&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# arcpy.CopyFeatures_management(citiesL, cityListFC)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# arcpy.Select_analysis(citiesL, cityListFC, "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.FeatureClassToShapefile_conversion(citiesL, path)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# make temp cities list feature layer so that the output can be spatially joined to counties&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# arcpy.MakeFeatureLayer_management(cityListFC,cityListL)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#arcpy.AddField_management(citiesL, "CITYNAME", "TEXT", "", "", "25")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#arcpy.AddField_management(citiesL, "CRIMEINDX", "DOUBLE", "", "", "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#arcpy.AddField_management(citiesL, "HAS_UNI", "TEXT", "", "", "3")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#arcpy.CalculateField_management(citiesL, "CITYNAME", "!NAME!", "PYTHON")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#arcpy.CalculateField_management(citiesL, "CRIMEINDX", "!CRIME_INDE!", "PYTHON")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#arcpy.CalculateField_management(citiesL, "HAS_UNI", "!UNIVERSITY!", "PYTHON")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#arcpy.DeleteField_management(citiesL,["NAME", "LABEL", "CLASS"])&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#arcpy.DeleteField_management(citiesL,["CRIME_INDE", "LABEL", "CLASS"])&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#arcpy.DeleteField_management(citiesL,["UNIVERSITY", "LABEL", "CLASS"])&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#arcpy.DeleteField_management(citiesL,["ID", "LABEL", "CLASS"])&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#arcpy.DeleteField_management(citiesL,["POPULATION", "LABEL", "CLASS"])&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#arcpy.DeleteField_management(citiesL,["TOTAL_CRIM", "LABEL", "CLASS"])&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Generate NearTable_analysis to find closest interstate distance&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.GenerateNearTable_analysis(citiesL, interstates, nearestInterstate, maxKmInterstate)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# join new city list layer to generated Near Table&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddJoin_management(citiesL, "NEAR_FID", nearestInterstate, "IN_FID")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Run the Spatial Join tool, using the defaults for the join operation and join type&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SpatialJoin_analysis(targetFeatures, joinFeatures, outputLayer, "#", "#", "#")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print arcpy.GetMessages()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print "\n*** LAST GEOPROCESSOR MESSAGE (may not be source of the error)***"; print arcpy.GetMessages()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print "Python Traceback Info: " + traceback.format_tb(sys.exc_info()[2])[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print "Python Error Info: " +&amp;nbsp; str(sys.exc_type)+ ": " + str(sys.exc_value)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# save selected features FINAL OOTPUT here&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# arcpy.CopyFeatures_management(citiesL, outputLayer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print arcpy.GetMessages()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[\CODE]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 15:49:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sql-where-caluse-syntax-please-help/m-p/167590#M12939</guid>
      <dc:creator>ScottMacDonald</dc:creator>
      <dc:date>2013-04-11T15:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: SQL where caluse syntax Please Help</title>
      <link>https://community.esri.com/t5/python-questions/sql-where-caluse-syntax-please-help/m-p/167591#M12940</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would follow Jake's suggestion, from a previous post of the exact same question, and simplify your script to more easily debug your issue with the SQL clause.&amp;nbsp; Once that problem has been resolved I would work towards getting your more complex code working.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 15:52:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sql-where-caluse-syntax-please-help/m-p/167591#M12940</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2013-04-11T15:52:12Z</dc:date>
    </item>
    <item>
      <title>Re: SQL where caluse syntax Please Help</title>
      <link>https://community.esri.com/t5/python-questions/sql-where-caluse-syntax-please-help/m-p/167592#M12941</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi thanks for your reply mvolz.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I wrote perfect working code last week that is hard-coded.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have already converted 95% of it to generic and it all works apart from the where clause expression.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That's the whole problem!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help with the syntax or maybe even how to print out what it's doing might help.&amp;nbsp; Is there any way to show exactly what its doing?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can't think of anything else I can do and it's still not right.&amp;nbsp; I'll keep working on it until the deadline.&amp;nbsp; All I want is &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"CRIME_INDE" &amp;lt;= 0.02 AND "UNIVERSITY" = 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"AGE_18_64" &amp;gt;= 25000 AND "NO_FARMS87" &amp;gt;=500&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That's it. Nothing else. Everything works apart from that!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can even # out the two GetLayerByAttribute lines and it works without the selected features.&amp;nbsp; It's ONLY the above two statements that are preventing the whole thing from running as perfectly as the hard coded version I wrote last week.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for you reply.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Scottaidh&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Apr 2013 17:13:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sql-where-caluse-syntax-please-help/m-p/167592#M12941</guid>
      <dc:creator>ScottMacDonald</dc:creator>
      <dc:date>2013-04-11T17:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: SQL where caluse syntax Please Help</title>
      <link>https://community.esri.com/t5/python-questions/sql-where-caluse-syntax-please-help/m-p/167593#M12942</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Scott,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Add the 'arcpy.AddMessage' function to your script to print out your where clauses:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.AddMessage(whereClause)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, what type of data are you working with? (i.e. shapefiles, File Geodatabase feature classes, Personal Geodatabase feature classes)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Apr 2013 09:39:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sql-where-caluse-syntax-please-help/m-p/167593#M12942</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2013-04-12T09:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: SQL where caluse syntax Please Help</title>
      <link>https://community.esri.com/t5/python-questions/sql-where-caluse-syntax-please-help/m-p/167594#M12943</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The key here is to know/remember that in Python the backslash is the escape character.&amp;nbsp; So you will need to use it to escape the special use of the quote character for defining text syntax.&amp;nbsp; The following syntax should accomplish what you need:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;field1 = "CRIME_INDEX"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;field2 = "UNIVERSITY"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;field3 = "AGE_18_64"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;field4 = "NO_FARMS87"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;SQL1 = "\"" + field1 + "\" &amp;lt;= 0.02 AND " + "\"" + field2 + "\" = 1"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SQL2 = "\"" + field3 + "\" &amp;gt;= 25000 AND " + "\"" + field4 + "\" &amp;gt;= 500"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As suggested above, if you use arcpy.AddMessage(SQL1) and arcpy.AddMessage(SQL2) you should see the appropriate where clause which you can pass to the Select By tools as a parameter.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Apr 2013 11:03:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sql-where-caluse-syntax-please-help/m-p/167594#M12943</guid>
      <dc:creator>AnthonyCalamito</dc:creator>
      <dc:date>2013-04-15T11:03:01Z</dc:date>
    </item>
    <item>
      <title>Re: SQL where caluse syntax Please Help</title>
      <link>https://community.esri.com/t5/python-questions/sql-where-caluse-syntax-please-help/m-p/167595#M12944</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you all very much for taking the time to reply.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The line that worked in the end was a Field Delimiter where clause&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;PRE&gt;&lt;/PRE&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;crimeField = arcpy.GetParameterAsText(4) # crimeField is fieldname 'CRIME_INDE' SQL expression&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;crimeval = arcpy.GetParameterAsText(5) # crime index is CRIME_INDE and is a Double 0.02&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;whereClause = "{0} &amp;lt;= {1}".format(arcpy.AddFieldDelimiters(citiesL, crimeField), crimeval)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[\CODE]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Previously, I had two extra ' single abbreviations around the where clause 0 and 1 which made the expression something like ""CRIME_INDE"" = "0.02" so watch out for them!&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for the help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Scottaidh&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Apr 2013 09:15:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sql-where-caluse-syntax-please-help/m-p/167595#M12944</guid>
      <dc:creator>ScottMacDonald</dc:creator>
      <dc:date>2013-04-16T09:15:54Z</dc:date>
    </item>
  </channel>
</rss>

