<?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 Query in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/sql-query/m-p/231234#M17924</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I might be mistaken, but I believe SQL requires strings to be enclosed in escaped single quotes (\'). So, your query would be:&lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;whereClause="[OBJECTID] = \'" + str(x) + "\'"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 11:13:51 GMT</pubDate>
    <dc:creator>DarrenWiens2</dc:creator>
    <dc:date>2021-12-11T11:13:51Z</dc:date>
    <item>
      <title>SQL Query</title>
      <link>https://community.esri.com/t5/python-questions/sql-query/m-p/231230#M17920</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I ve problems with a sql expression. I want to select one row of a 1st lyr file attribute table in order to only select those features from a2nd lyr file intersecting with the 1lyr selected feature.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried all kind of expressions: "" ,"/", etc. but it keeps telling me either the expression is wrong or it doesn't make any selection. Any ideas?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thi is the part of code keeping troubleing me&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
rows = arcpy.SearchCursor(MU)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; x=row.OBJECTID
&amp;nbsp;&amp;nbsp;&amp;nbsp; whereClause="[OBJECTID] = "+str(x)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management (lyrFile, "NEW_SELECTION", whereClause)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management(lyrFile2, "intersect", selectFeatures) &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:12:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sql-query/m-p/231230#M17920</guid>
      <dc:creator>chriss_</dc:creator>
      <dc:date>2021-12-12T16:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Query</title>
      <link>https://community.esri.com/t5/python-questions/sql-query/m-p/231231#M17921</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here's a couple of thoughts:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Using [OBJECTID] indicates that your data is stored in a personal geodatabase (.mdb). If it isn't, you should be using "OBJECTID" instead.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Assuming #1 is correct, it might be easier to use string substitution to build your query:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]whereClause = "[OBJECTID] = %d" % row.OBJECTID[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and omit the line 'x=row.OBJECTID'.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3. If you're not querying a personal GDB, the query statement would be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]whereClause = '"OBJECTID" = %d' % row.OBJECTID[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Jun 2011 11:43:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sql-query/m-p/231231#M17921</guid>
      <dc:creator>BruceNielsen</dc:creator>
      <dc:date>2011-06-02T11:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Query</title>
      <link>https://community.esri.com/t5/python-questions/sql-query/m-p/231232#M17922</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;To debug a tool, try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Run a tool interactively by filling in the dialog by hand.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;After it runs successfully, open the results and right-click to get "Copy as a Python Snippet"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Paste this into an empty Python script and examine the syntax, particularly the SQL query.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I find that provided you are not using a personal geodatabase (*.mdb) AND you are using valid field names (No spaces or silly chars, starts with a letter, less than max chars, not a reserved word) you can also dispense with the double quotes around the field names. In spite of the help saying otherwise. This makes assembling SQL queries much simpler. Also try printing out your expression to see if you really got the expected valid expression.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Jun 2011 01:22:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sql-query/m-p/231232#M17922</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2011-06-03T01:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Query</title>
      <link>https://community.esri.com/t5/python-questions/sql-query/m-p/231233#M17923</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks to both of you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Finally I discovered that it was not my SQL Query that didnt work. The problem lies within the "arcpy.SelectLayerByLocation_management" i couldnt get it to work so i changed to "Intersect_analysis" what is better anyhow.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;@kimo&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I really appreciate debugging advice. Normally for coding, I use the standard python window that comes with python. But compared to typing directly in the arcgis python window i get less "advice". By "advice" i mean arcgis python automatically pops up a list with functions or wahtever i can enter at this point. e.g. i type "arcpy." and then it pops up all functions arcpy has. in the standard python window it doesnt. Where do you write your code? Any tipps are highly appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Jun 2011 03:32:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sql-query/m-p/231233#M17923</guid>
      <dc:creator>chriss_</dc:creator>
      <dc:date>2011-06-03T03:32:12Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Query</title>
      <link>https://community.esri.com/t5/python-questions/sql-query/m-p/231234#M17924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I might be mistaken, but I believe SQL requires strings to be enclosed in escaped single quotes (\'). So, your query would be:&lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;whereClause="[OBJECTID] = \'" + str(x) + "\'"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:13:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sql-query/m-p/231234#M17924</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T11:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Query</title>
      <link>https://community.esri.com/t5/python-questions/sql-query/m-p/231235#M17925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Intellisense works just fine in PythonWin while coding if you first &lt;/SPAN&gt;&lt;STRONG&gt;import arcpy&lt;/STRONG&gt;&lt;SPAN&gt; in the Interactive Window. No need to go to some other IDE.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;import arcpy&lt;/STRONG&gt;&lt;SPAN&gt; will check out a licence but it will make Pythonwin aware of the module.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you only have an arcview licence, then &lt;/SPAN&gt;&lt;STRONG&gt;import arcview&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can also then browse the arcpy module from Menu&amp;gt;Tools&amp;gt;Browser&amp;gt; arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;instead of the default __builtins__&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However I still find the commentary in the ArcGIS help more useful.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jun 2011 06:50:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sql-query/m-p/231235#M17925</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2011-06-06T06:50:49Z</dc:date>
    </item>
  </channel>
</rss>

