<?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: SelectLayerByAttribute_analysis HELP!! in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563581#M44079</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the tips. I know the code is very sloppy, but I know I have "" '' formatting correct. Its the SQL expression that is not correct. I tried using the In format but still no dice. I can't seem to find anything online about the correct SQL expression to use in arcpy to obtain more than feature by attribute.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Jan 2014 16:58:58 GMT</pubDate>
    <dc:creator>DonaldFiore</dc:creator>
    <dc:date>2014-01-10T16:58:58Z</dc:date>
    <item>
      <title>SelectLayerByAttribute_analysis HELP!!</title>
      <link>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563578#M44076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey all, starting to get frustrated, if anyone can lend some clarity it'd be greatly appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.SelectLayerByAttribute_management('mwstates','NEW_SELECTION','"STATE_NAME"=\'Illinois\' or '"STATE_NAME"=\'Indiana\'' &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Code keeps returning only 'Illinois', (I want both 'Illinois' and 'Indiana') I've tried numerous variations. I think I have to be missing something obvious here. Thoughts??&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jan 2014 14:21:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563578#M44076</guid>
      <dc:creator>DonaldFiore</dc:creator>
      <dc:date>2014-01-10T14:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: SelectLayerByAttribute_analysis HELP!!</title>
      <link>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563579#M44077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How about something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management('mwstates','NEW_SELECTION',"STATE_NAME in ('Illinois' , 'Indiana')")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This syntax works in a python script I have using Select_analysis against an SDE database.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jan 2014 14:49:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563579#M44077</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2014-01-10T14:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: SelectLayerByAttribute_analysis HELP!!</title>
      <link>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563580#M44078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Doesn't look like you pasted all of your query...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If this helps, you could 'escape' all of your quotation characters with the backwards slash, \' and \", like so:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; query = '\"STATE_NAME\"=\'Illinois\' or \'\"STATE_NAME\"=\'Indiana\''

&amp;gt;&amp;gt;&amp;gt; print query
"STATE_NAME"='Illinois' or '"STATE_NAME"='Indiana'
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...or even use the built-in python format in various ways - here is one of them (and I changed the SQL syntax, using the IN operator):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; query = '{0} IN ({1}, {2})'.format('"STATE_NAME"', "'Indiana'", "'Illinois'")

&amp;gt;&amp;gt;&amp;gt; print query
"STATE_NAME" IN ('Indiana', 'Illinois')
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...FYI, if it makes the code more readable as well, you could define a var (as I've done with 'query') and pass that to your Select by attributes:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
arcpy.SelectLayerByAttribute_management('mwstates','NEW_SELECTION',query)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:17:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563580#M44078</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-12T00:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: SelectLayerByAttribute_analysis HELP!!</title>
      <link>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563581#M44079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the tips. I know the code is very sloppy, but I know I have "" '' formatting correct. Its the SQL expression that is not correct. I tried using the In format but still no dice. I can't seem to find anything online about the correct SQL expression to use in arcpy to obtain more than feature by attribute.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jan 2014 16:58:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563581#M44079</guid>
      <dc:creator>DonaldFiore</dc:creator>
      <dc:date>2014-01-10T16:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: SelectLayerByAttribute_analysis HELP!!</title>
      <link>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563582#M44080</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;What do you mean exactly?&amp;nbsp; There are references - you can start here:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Building a query expression&lt;/SPAN&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/main/10.2/index.html#//00s50000002t000000" rel="nofollow" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.2/index.html#//00s50000002t000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...and if you look in the 'tree' view panel to the left (if you have it visible in your browser), there's another subtopic, "SQL reference..."&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want to use it, there's also an AddFieldDelimiters command, in case you want a universal query for sources out of different workspace types -- I think a personal gdb used brackets on the field, etc etc....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also try forming the query with the select wizard in ArcMap to 'see' the correct sytax....other than that, make sure you are selecting what you think you're selecting i.e. that the attribute value is actually in there somewhere.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;BTW:&amp;nbsp; (extra single-quote)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Like I said before, maybe you pasted in error, but your query posted is NOT correct:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt; '"STATE_NAME"=\'Illinois\' or '"STATE_NAME"=\'Indiana\'' SyntaxError: unexpected character after line continuation character &amp;gt;&amp;gt;&amp;gt; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You have and 'extra' single-quote before "STATE_NAME" - this works:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt; '&amp;nbsp; "STATE_NAME"=\'Illinois\' or "STATE_NAME"=\'Indiana\'&amp;nbsp; ' '&amp;nbsp; "STATE_NAME"=\'Illinois\' or "STATE_NAME"=\'Indiana\'&amp;nbsp; ' &amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jan 2014 17:20:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563582#M44080</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2014-01-10T17:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: SelectLayerByAttribute_analysis HELP!!</title>
      <link>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563583#M44081</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are you running this in a standalone python script outside of ArcMap or are you using the Field Calculator?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe you can use the Field Calculator with python inside ArcMap to get the syntax correct.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jan 2014 17:54:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563583#M44081</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2014-01-10T17:54:35Z</dc:date>
    </item>
    <item>
      <title>Re: SelectLayerByAttribute_analysis HELP!!</title>
      <link>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563584#M44082</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok! Got It! Thanks for recommending running the wizard in arcmap, I forgot you could pull py snippets of script from the geoprocessing window.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Correct Script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management("mwstates","NEW_SELECTION","STATE_NAME = 'Illinois' OR STATE_NAME = 'Indiana'")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was encasing the Field (State_Name) in double quotes, apparently only the expression itself needs to be encased.&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, 10 Jan 2014 17:56:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563584#M44082</guid>
      <dc:creator>DonaldFiore</dc:creator>
      <dc:date>2014-01-10T17:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: SelectLayerByAttribute_analysis HELP!!</title>
      <link>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563585#M44083</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Beautiful.&amp;nbsp; Welcome to the forums!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, the 'correct' etiquette, if you haven't already done so, is to award points to various valuable posts or the 'green checkmark' to that single post you deem the best answer (before you log out).&amp;nbsp; Those are the buttons to the right of the posts...fiddle with those.&amp;nbsp; You can even give yourself the answer if you want...lol.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jan 2014 18:07:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563585#M44083</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2014-01-10T18:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: SelectLayerByAttribute_analysis HELP!!</title>
      <link>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563586#M44084</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;There is another way you can make this query easier on yourself.&amp;nbsp; I just found this gem the other day...Apparently you can form queries using a list like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
query = ''' "STATE_NAME" IN ('Illinois', 'Indiana') '''
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:17:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/selectlayerbyattribute-analysis-help/m-p/563586#M44084</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T00:17:34Z</dc:date>
    </item>
  </channel>
</rss>

