<?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: Where Clause with AND Statement in Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/where-clause-with-and-statement-in-python/m-p/550228#M43026</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check out &lt;A _jive_internal="true" href="https://community.esri.com/blogs/dan_patterson/2016/03/01/fancy-fancy-formatting"&gt;&lt;STRONG&gt;Fancy, Fancy Formatting&lt;/STRONG&gt; &lt;/A&gt;and the links in there on Basic Fancy Formatting etc.&lt;/P&gt;&lt;P&gt;As you move to python 3, this will become more useful over time,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 11 Sep 2017 18:07:47 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2017-09-11T18:07:47Z</dc:date>
    <item>
      <title>Where Clause with AND Statement in Python</title>
      <link>https://community.esri.com/t5/python-questions/where-clause-with-and-statement-in-python/m-p/550227#M43025</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In&amp;nbsp;&lt;A href="https://community.esri.com/thread/201367" target="_blank"&gt;Adding to a Selection&lt;/A&gt;&amp;nbsp;I asked how to pass&amp;nbsp;a variable set in a search cursor to a where statement. &lt;A href="https://community.esri.com/migrated-users/3355" target="_blank"&gt;Curtis Price&lt;/A&gt; helped me there. &amp;nbsp;That turned out to be only half of what I need in the particular application I'm working on: &amp;nbsp;I also need to incorporate an AND statement into the WHERE clause. &amp;nbsp;It's all about pythons' love of lists...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Curtis provided the initial where clause and I expand upon it below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;where &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;"&gt;=&lt;/SPAN&gt; &lt;SPAN class="" style="color: #669900; border: 0px; font-weight: inherit;"&gt;"FullStreet IN ({})"&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;(&lt;/SPAN&gt;street_list&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;)
&lt;/SPAN&gt;&lt;/CODE&gt;#which creates a selection where FullStreet is a member of street_list
# I change his where variable to this:
where = "FullStreet IN ({}) AND numeric_hn &amp;lt;=({}) AND numeric_hn &amp;gt;= ({})".format(street_list,max,min)
# so I'm selecting not only for the FullStreet value, but checking for a house number value that
#is GTE and LTE to specified values
arcpy.SelectLayerByAttribute_management ("apLayer","ADD_TO_SELECTION",where)
#And I'm golden!


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the newbie like myself, each of the ({}) gets populated with the corresponding (in order) list member. &amp;nbsp;So:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FullStreet IN ({street_list})&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;numeric_hn &amp;lt;= ({max})&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;numeric_hn =&amp;gt; ({min})&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is&amp;nbsp;how the where statement is being interpreted. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lessons learned:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Quote positions are critical&lt;/P&gt;&lt;P&gt;The .format method is your friend. &amp;nbsp;Sometimes he can be a difficult friend, but he's a friend.&lt;/P&gt;&lt;P&gt;Python is all about lists. &amp;nbsp;Don't overlook or forget that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kudos&amp;nbsp;to &lt;A href="https://community.esri.com/migrated-users/6462" target="_blank"&gt;Ryan Sadler&lt;/A&gt;‌ for teaching this old dawg a new trick&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/19932" target="_blank"&gt;Darren Wiens&lt;/A&gt;‌ , &lt;A href="https://community.esri.com/migrated-users/2691" target="_blank"&gt;Rebecca Strauch, GISP&lt;/A&gt;‌&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:48:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-clause-with-and-statement-in-python/m-p/550227#M43025</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-12-11T23:48:20Z</dc:date>
    </item>
    <item>
      <title>Re: Where Clause with AND Statement in Python</title>
      <link>https://community.esri.com/t5/python-questions/where-clause-with-and-statement-in-python/m-p/550228#M43026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check out &lt;A _jive_internal="true" href="https://community.esri.com/blogs/dan_patterson/2016/03/01/fancy-fancy-formatting"&gt;&lt;STRONG&gt;Fancy, Fancy Formatting&lt;/STRONG&gt; &lt;/A&gt;and the links in there on Basic Fancy Formatting etc.&lt;/P&gt;&lt;P&gt;As you move to python 3, this will become more useful over time,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Sep 2017 18:07:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-clause-with-and-statement-in-python/m-p/550228#M43026</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-09-11T18:07:47Z</dc:date>
    </item>
  </channel>
</rss>

