<?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: select by attributes using like in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/select-by-attributes-using-like/m-p/27775#M2124</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We're using SDE. &amp;nbsp;and I'm not comparing a string against a field, I'm comparing one field against another, so I couldn't escape the underscores - they're in the source data. &amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 25 Sep 2017 13:05:26 GMT</pubDate>
    <dc:creator>ColinLang1</dc:creator>
    <dc:date>2017-09-25T13:05:26Z</dc:date>
    <item>
      <title>select by attributes using like</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attributes-using-like/m-p/27771#M2120</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to do a Select By Attributes where I have a field in one street file that has a column "POLICE" that lists the police department like this example:&lt;STRONG&gt; 'Sussex Police'&lt;/STRONG&gt; and a file from another source that I am joining that has a column "Police" that lists the police department like this example: &lt;STRONG&gt;'SUSSEX_POLICE'&lt;/STRONG&gt;. &amp;nbsp;For some names, there may be multiple underscore characters. &amp;nbsp;I can obviously use UPPER() on the first field to make them almost match, and on the off chance that the data isn't consistent, I'm actually using UPPER on both sides. &amp;nbsp;I was hoping I could use LIKE to get the underscore vs. the space, but it's just not matching. &amp;nbsp;So this is my current expression:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp;where = 'UPPER("EmergencyServiceZones.POLICE") LIKE UPPER("msag_temp.Police")'&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;arcpy.SelectLayerByAttribute_management (road_layer, "NEW_SELECTION", where)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It returns nothing as it is.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does anyone have any suggestions to adjust the query expression to find the matches?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Sep 2017 17:27:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attributes-using-like/m-p/27771#M2120</guid>
      <dc:creator>ColinLang1</dc:creator>
      <dc:date>2017-09-22T17:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: select by attributes using like</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attributes-using-like/m-p/27772#M2121</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did you try:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM style="background-color: #ffffff; border: 0px;"&gt;where = 'UPPER("EmergencyServiceZones.POLICE") &lt;STRONG&gt;=&lt;/STRONG&gt; UPPER("msag_temp.Police")'&amp;nbsp;&lt;/EM&gt;?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Sep 2017 17:46:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attributes-using-like/m-p/27772#M2121</guid>
      <dc:creator>MitchHolley1</dc:creator>
      <dc:date>2017-09-22T17:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: select by attributes using like</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attributes-using-like/m-p/27773#M2122</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;They're definitely not equal. &amp;nbsp;Like was my only hope. &amp;nbsp;I have found the solution, and it's a head-scratcher....&amp;nbsp;&lt;/P&gt;&lt;P&gt;this fails:&amp;nbsp;&lt;EM style="background-color: #ffffff; border: 0px;"&gt;where = 'UPPER("EmergencyServiceZones.POLICE") LIKE UPPER("msag_temp.Police")'&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;this works:&amp;nbsp;&lt;EM style="background-color: #ffffff; border: 0px;"&gt;where = 'UPPER("msag_temp.Police") LIKE&amp;nbsp;UPPER("EmergencyServiceZones.POLICE")'&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for some bizarre reason, a space is LIKE an underscore, but an underscore is not LIKE a space.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Sep 2017 18:11:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attributes-using-like/m-p/27773#M2122</guid>
      <dc:creator>ColinLang1</dc:creator>
      <dc:date>2017-09-22T18:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: select by attributes using like</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attributes-using-like/m-p/27774#M2123</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You didn't state what the back-end data store is, but an underscore character is commonly a single-character wildcard in SQL LIKE operators.&amp;nbsp; Since you didn't escape the underscore, you are effectively inserting a wildcard into your search, which affects the results.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Sep 2017 22:42:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attributes-using-like/m-p/27774#M2123</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2017-09-22T22:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: select by attributes using like</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attributes-using-like/m-p/27775#M2124</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We're using SDE. &amp;nbsp;and I'm not comparing a string against a field, I'm comparing one field against another, so I couldn't escape the underscores - they're in the source data. &amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Sep 2017 13:05:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attributes-using-like/m-p/27775#M2124</guid>
      <dc:creator>ColinLang1</dc:creator>
      <dc:date>2017-09-25T13:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: select by attributes using like</title>
      <link>https://community.esri.com/t5/python-questions/select-by-attributes-using-like/m-p/27776#M2125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can handle the underscores just like you can handle the case differences, i.e., by either calling another SQL function or calling an existing one differently.&amp;nbsp; For example with SQL Server (and maybe other DMBSs), LIKE has an &lt;EM&gt;escape_character&lt;/EM&gt; argument that can be used.&amp;nbsp; Since you are already calling UPPER, you aren't really comparing the source data any longer but modified copies of the source data ("SUSSEX POLICE" instead of "Sussex Police."&amp;nbsp; A&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Sep 2017 16:03:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-by-attributes-using-like/m-p/27776#M2125</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2017-09-25T16:03:01Z</dc:date>
    </item>
  </channel>
</rss>

