<?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: Looking for proper syntax for SQL expression in Python to select features by attribute in Python Snippets Questions</title>
    <link>https://community.esri.com/t5/python-snippets-questions/looking-for-proper-syntax-for-sql-expression-in/m-p/817419#M328</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, it worked like a charm!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 19 Apr 2017 21:51:21 GMT</pubDate>
    <dc:creator>deleted-user-AOHsGDn8SRw7</dc:creator>
    <dc:date>2017-04-19T21:51:21Z</dc:date>
    <item>
      <title>Looking for proper syntax for SQL expression in Python to select features by attribute</title>
      <link>https://community.esri.com/t5/python-snippets-questions/looking-for-proper-syntax-for-sql-expression-in/m-p/817417#M326</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to create a simple code that will select features in a shapefile based on the query {anything within the ATTRIBUTE field that starts with the letter 'P'}. Here&amp;nbsp;the problematic line:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;EM&gt;arcpy.SelectLayerByAttribute_management("NJ_Wetlands", "NEW_SELECTION", """"ATTRIBUTE" LIKE P%""")&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know I could do this simply in the toolbox GUI, but I'm trying to learn arcpy. I'm obviously doing something wrong, and it shouldn't be very complicated. I get the error:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;EM&gt;Runtime error Traceback (most recent call last): File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt; File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\management.py", line 7713, in SelectLayerByAttribute raise e ExecuteError: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute).&lt;/EM&gt; &lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P&gt;I've already tried searching through&amp;nbsp;various forums and some help guides on Esri.com, but no dice. I guess I need this help to be explained very&amp;nbsp;explicitly, otherwise I am lost.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Apr 2017 16:36:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/looking-for-proper-syntax-for-sql-expression-in/m-p/817417#M326</guid>
      <dc:creator>deleted-user-AOHsGDn8SRw7</dc:creator>
      <dc:date>2017-04-19T16:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for proper syntax for SQL expression in Python to select features by attribute</title>
      <link>https://community.esri.com/t5/python-snippets-questions/looking-for-proper-syntax-for-sql-expression-in/m-p/817418#M327</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SelectLayerByAttribute_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"NJ_Wetlands"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"NEW_SELECTION"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"ATTRIBUTE LIKE 'P%'"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Since you are wanting to learn Python, I encourage you to read &lt;A href="https://docs.python.org/2/reference/lexical_analysis.html#string-literals"&gt;String literals &lt;/A&gt;section of the Lexical analysis Python documentation.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Apr 2017 16:49:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/looking-for-proper-syntax-for-sql-expression-in/m-p/817418#M327</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2017-04-19T16:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for proper syntax for SQL expression in Python to select features by attribute</title>
      <link>https://community.esri.com/t5/python-snippets-questions/looking-for-proper-syntax-for-sql-expression-in/m-p/817419#M328</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, it worked like a charm!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Apr 2017 21:51:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/looking-for-proper-syntax-for-sql-expression-in/m-p/817419#M328</guid>
      <dc:creator>deleted-user-AOHsGDn8SRw7</dc:creator>
      <dc:date>2017-04-19T21:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for proper syntax for SQL expression in Python to select features by attribute</title>
      <link>https://community.esri.com/t5/python-snippets-questions/looking-for-proper-syntax-for-sql-expression-in/m-p/817420#M329</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please mark an answer correct to close out the question, thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Apr 2017 13:40:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/looking-for-proper-syntax-for-sql-expression-in/m-p/817420#M329</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2017-04-20T13:40:27Z</dc:date>
    </item>
  </channel>
</rss>

