<?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: Invalid SQL Statement SelectLayerByLocation in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/invalid-sql-statement-selectlayerbylocation/m-p/84119#M6642</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Turns out that the first make feature layer method was using an SQL statement that was resulting in an empty layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I changed:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.MakeFeatureLayer_management ("FishnetPoly.shp", "FishnetCell", '"SplitField" = ' + str(i), gp.Workspace, "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.MakeFeatureLayer_management ("FishnetPoly.shp", "FishnetCell", '"SplitField" = ' + "'" + str(i) + "'", gp.Workspace, "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;because the field I was selecting is a text field, even though it contains a number, str(i) needed single quotes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That solved the problem.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Oct 2011 19:46:27 GMT</pubDate>
    <dc:creator>LornaMurison</dc:creator>
    <dc:date>2011-10-20T19:46:27Z</dc:date>
    <item>
      <title>Invalid SQL Statement SelectLayerByLocation</title>
      <link>https://community.esri.com/t5/python-questions/invalid-sql-statement-selectlayerbylocation/m-p/84118#M6641</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey everyone,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The following is the first thing that my script does after setting up variables etc...&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# Create Fishnet
desc = gp.describe (streams)
xmin = desc.extent.xmin
ymin = desc.extent.ymin
xmax = desc.extent.xmax
ymax = desc.extent.ymax
origin_coord = str (xmin) + " " + str(ymin)
y_axis_coord = str (xmin) + " " + str(ymin + 10)
corner_coord = str (xmax) + " " + str(ymax)
gp.CreateFishnet_management ("Fishnet.shp", origin_coord, y_axis_coord, 0, 0, 2, 2, corner_coord, "NO_LABELS", "")

# Convert the Fishnet to Polygon
gp.FeatureToPolygon_management("Fishnet.shp", "FishnetPoly.shp", "#", "NO_ATTRIBUTES", "")

# Calculate ID Field with Incremental number
gp.CalculateField_management("FishnetPoly.shp", "id", "autoIncrement()", "PYTHON_9.3", "rec=0\\ndef autoIncrement():\\n global rec\\n pStart = 1 #adjust start value, if req'd \\n pInterval = 1 #adjust interval value, if req'd\\n if (rec == 0): \\n&amp;nbsp; rec = pStart \\n else: \\n&amp;nbsp; rec = rec + pInterval \\n return rec")

# Add and Calculate Text Field (SplitField) With That Same Number
gp.AddField_management("FishnetPoly.shp", "SplitField", "TEXT", "#", "#", 1, "", "NULLABLE", "NON_REQUIRED", "")
gp.CalculateField_management("FishnetPoly.shp", "SplitField", '"id"', "VB", "")

# Loop Through Each FishnetPoly Cell and Select Those Catchments That Have Their Center In The Given Cell
for i in range (1,5,1):
&amp;nbsp;&amp;nbsp;&amp;nbsp; ### Make Feature Layer From First Fishnet Cell
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.MakeFeatureLayer_management ("FishnetPoly.shp", "FishnetCell", '"SplitField" = ' + str(i), gp.Workspace, "")

&amp;nbsp;&amp;nbsp;&amp;nbsp; ### Make Feature Layer From Catchments
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.MakeFeatureLayer_management (catchments, "CatchmentsLayer", "", gp.Workspace, "")

&amp;nbsp;&amp;nbsp;&amp;nbsp; ### Select Catchments Which Have Their Center in the Feature Layer Cell
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SelectLayerByLocation_management ("CatchmentsLayer", "HAVE_THEIR_CENTER_IN", "FishnetCell")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It returns the following error at gp.SelectLayerByLocation_management...&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;ExecuteError: ERROR 999999: Error executing function.
An invalid SQL statement was used.
An invalid SQL statement was used.
A locator with this name does not exist.
Failed to execute (SelectLayerByLocation).&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;I have no idea why.&amp;nbsp; I don't know what SQL statement it could be referring to.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Oct 2011 18:32:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/invalid-sql-statement-selectlayerbylocation/m-p/84118#M6641</guid>
      <dc:creator>LornaMurison</dc:creator>
      <dc:date>2011-10-20T18:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid SQL Statement SelectLayerByLocation</title>
      <link>https://community.esri.com/t5/python-questions/invalid-sql-statement-selectlayerbylocation/m-p/84119#M6642</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Turns out that the first make feature layer method was using an SQL statement that was resulting in an empty layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I changed:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.MakeFeatureLayer_management ("FishnetPoly.shp", "FishnetCell", '"SplitField" = ' + str(i), gp.Workspace, "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.MakeFeatureLayer_management ("FishnetPoly.shp", "FishnetCell", '"SplitField" = ' + "'" + str(i) + "'", gp.Workspace, "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;because the field I was selecting is a text field, even though it contains a number, str(i) needed single quotes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That solved the problem.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Oct 2011 19:46:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/invalid-sql-statement-selectlayerbylocation/m-p/84119#M6642</guid>
      <dc:creator>LornaMurison</dc:creator>
      <dc:date>2011-10-20T19:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: Invalid SQL Statement SelectLayerByLocation</title>
      <link>https://community.esri.com/t5/python-questions/invalid-sql-statement-selectlayerbylocation/m-p/84120#M6643</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks...struggled with this one for a while before I found your post.&amp;nbsp; Pulling a number from a text column required extra single quote around the number.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Sep 2012 19:09:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/invalid-sql-statement-selectlayerbylocation/m-p/84120#M6643</guid>
      <dc:creator>DaveJohnson</dc:creator>
      <dc:date>2012-09-14T19:09:05Z</dc:date>
    </item>
  </channel>
</rss>

