<?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 issue with creating of the where_clause in ArcPy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/issue-with-creating-of-the-where-clause-in-arcpy/m-p/1122596#M63132</link>
    <description>&lt;P&gt;I would like to create a query in ArcPy without creating a temporary additional attribute first. Unfortunately I fail with the syntax for creating the expression. I want to check if a ratio of two existing attributes (RCT_WIDTH_MBG_Length_REWI and RCT_WIDTH_MBG_Width_REWID) falls below a certain value.&lt;/P&gt;&lt;P&gt;My latest code is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    expression = '!RCT_WIDTH_MBG_Length_REWI! / !RCT_WIDTH_MBG_Width_REWID! &amp;gt; 3' 
    arcpy.SelectLayerByAttribute_management('Clean_LYR', 'NEW_SELECTION', expression)
    if int(arcpy.GetCount_management('Clean_LYR')[0]) &amp;gt; 0:
        arcpy.DeleteFeatures_management('Clean_LYR')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;and during the script run I code the error message:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;ExecuteError: ERROR 000358: Invalid expression&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;My question is, how will be the right syntax of the expression?&lt;/P&gt;</description>
    <pubDate>Fri, 03 Dec 2021 18:16:39 GMT</pubDate>
    <dc:creator>AlfonsZitterbacke</dc:creator>
    <dc:date>2021-12-03T18:16:39Z</dc:date>
    <item>
      <title>issue with creating of the where_clause in ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/issue-with-creating-of-the-where-clause-in-arcpy/m-p/1122596#M63132</link>
      <description>&lt;P&gt;I would like to create a query in ArcPy without creating a temporary additional attribute first. Unfortunately I fail with the syntax for creating the expression. I want to check if a ratio of two existing attributes (RCT_WIDTH_MBG_Length_REWI and RCT_WIDTH_MBG_Width_REWID) falls below a certain value.&lt;/P&gt;&lt;P&gt;My latest code is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    expression = '!RCT_WIDTH_MBG_Length_REWI! / !RCT_WIDTH_MBG_Width_REWID! &amp;gt; 3' 
    arcpy.SelectLayerByAttribute_management('Clean_LYR', 'NEW_SELECTION', expression)
    if int(arcpy.GetCount_management('Clean_LYR')[0]) &amp;gt; 0:
        arcpy.DeleteFeatures_management('Clean_LYR')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;and during the script run I code the error message:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;ExecuteError: ERROR 000358: Invalid expression&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;My question is, how will be the right syntax of the expression?&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2021 18:16:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-with-creating-of-the-where-clause-in-arcpy/m-p/1122596#M63132</guid>
      <dc:creator>AlfonsZitterbacke</dc:creator>
      <dc:date>2021-12-03T18:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: issue with creating of the where_clause in ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/issue-with-creating-of-the-where-clause-in-arcpy/m-p/1122605#M63133</link>
      <description>&lt;P&gt;try:&lt;/P&gt;&lt;P&gt;- set expression_type to &lt;SPAN&gt;PYTHON3&lt;/SPAN&gt; or PYTHON_9.3&lt;/P&gt;&lt;P&gt;- convert your inputs into integer (int(!RCT_WIDTH_MBG_Length_REWI!)&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally, run that in arcmap/ or in PRo manually, go to history and see how it was written (copy python snippet).&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2021 18:31:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-with-creating-of-the-where-clause-in-arcpy/m-p/1122605#M63133</guid>
      <dc:creator>Tomasz_Tarchalski</dc:creator>
      <dc:date>2021-12-03T18:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: issue with creating of the where_clause in ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/issue-with-creating-of-the-where-clause-in-arcpy/m-p/1122637#M63135</link>
      <description>&lt;P&gt;Your expression needs to be SQl compatible, not arcpy or python compatible.&amp;nbsp; I think the !FieldName! references are what is sinking your ship.&amp;nbsp; Here are a couple of examples of select expressions I have used in the past:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#UNIQUE_ID is a Character Type of Field...

expression = "UNIQUE_ID = '0' Or UNIQUE_ID IS NULL"

expression = 'CAST(UNIQUE_ID as INT) &amp;gt;= 15000000'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One way to test selection expressions with the the select tool.&amp;nbsp; Here I am using ArcGIS Pro with&amp;nbsp; two numeric fields:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoeBorgione_0-1638560521006.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/28806i8F34E6B066A6A5C6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JoeBorgione_0-1638560521006.png" alt="JoeBorgione_0-1638560521006.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2021 19:43:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-with-creating-of-the-where-clause-in-arcpy/m-p/1122637#M63135</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-12-03T19:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: issue with creating of the where_clause in ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/issue-with-creating-of-the-where-clause-in-arcpy/m-p/1122643#M63136</link>
      <description>&lt;P&gt;Hey Alfons&lt;/P&gt;&lt;P&gt;below is a piece of code that is similar that what you are trying to achieve.&lt;/P&gt;&lt;P&gt;1) Make sure you are using the FIELD Name and not the aliases&lt;/P&gt;&lt;P&gt;2) make you your formula returns valid values (no division /0...)&lt;/P&gt;&lt;P&gt;That should works! Good luck!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    arcpy.MakeFeatureLayer_management(sdeFCT, MFL,"TOTPOP10 &amp;gt;0 and ALAND10 &amp;gt;0")
    print(arcpy.GetCount_management(MFL))

    expression = '("ALAND10"/"TOTPOP10") &amp;gt; 1000'
    print(expression)
    arcpy.SelectLayerByAttribute_management(MFL, 'NEW_SELECTION', where_clause=expression)
    if int(arcpy.GetCount_management(MFL)[0]) &amp;gt; 0:
        print("delete records")
        ##arcpy.DeleteFeatures_management(sdeFCT)
    else:
        print("good to go")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2021 20:03:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issue-with-creating-of-the-where-clause-in-arcpy/m-p/1122643#M63136</guid>
      <dc:creator>DominicRobergeIADOT</dc:creator>
      <dc:date>2021-12-03T20:03:02Z</dc:date>
    </item>
  </channel>
</rss>

