<?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: Use a SQL expression inside a Python or Arcade field calculation? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/use-a-sql-expression-inside-a-python-or-arcade/m-p/1280151#M67458</link>
    <description>&lt;P&gt;Interestingly, SQL &lt;STRONG&gt;is&lt;/STRONG&gt; an option when using the field calculator on a hosted feature service.&lt;/P&gt;&lt;P&gt;For file geodatabase feature classes, I'd recommend taking a look at the "where_clause" and "sql_clause" parameters on the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/updatecursor-class.htm" target="_self"&gt;UpdateCursor&lt;/A&gt;. This might enable your desired workflow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Apr 2023 13:33:39 GMT</pubDate>
    <dc:creator>DannyMcVey</dc:creator>
    <dc:date>2023-04-19T13:33:39Z</dc:date>
    <item>
      <title>Use a SQL expression inside a Python or Arcade field calculation?</title>
      <link>https://community.esri.com/t5/python-questions/use-a-sql-expression-inside-a-python-or-arcade/m-p/1280050#M67454</link>
      <description>&lt;P&gt;&lt;EM&gt;ArcGIS Pro 3.1.1&lt;/EM&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;EM&gt;Mobile geodatabase,&lt;/EM&gt;&lt;/LI&gt;&lt;LI&gt;&lt;EM&gt;File geodatabase, &lt;/EM&gt;&lt;/LI&gt;&lt;LI&gt;&lt;EM&gt;Or enterprise geodatabase that is registered as versioned; &lt;U&gt;option to move edits to base&lt;/U&gt; (SQL field calculations not supported on versioned data):&lt;BR /&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;For cases where we would rather use SQL than Python or Arcade, is there a way to generate a value using a SQL expression -- that would be returned back to the Field Calculator geoprocessing tool?&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bud_1-1681882819177.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/68364i7CDCF9B914DFC952/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bud_1-1681882819177.png" alt="Bud_1-1681882819177.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;For example, if I already have a &lt;A href="https://i.stack.imgur.com/aC6pb.png" target="_self"&gt;complex SQL CASE expression&lt;/A&gt; written from a different use case, I don't want to re-write it in Python or Arcade. I'd rather just use the SQL as-is instead,&amp;nbsp;to save time and avoid mistakes.&lt;/P&gt;&lt;P&gt;I'm aware that it's possible to create a SQL database view, join it to the FC attribute table, and do a field calculation to bring in the joined field value. But that's pretty cumbersome for a one-off calculation. So I'm wondering if there's a way to use the SQL expression directly in a Python or Arcade field calculation instead.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Related ideas:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://community.esri.com/t5/arcgis-pro-ideas/virtual-attributes-ad-hoc/idi-p/1276471" target="_self"&gt;Virtual Attributes (ad hoc)&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://community.esri.com/t5/arcgis-pro-ideas/mobile-geodatabase-calculate-field-using-sql/idi-p/1272248" target="_self"&gt;Mobile Geodatabase — Calculate field using SQL&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://community.esri.com/t5/arcgis-pro-ideas/mobile-geodatabase-query-layers/idi-p/1237539" target="_self"&gt;Mobile geodatabase query layers&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://community.esri.com/t5/arcgis-pro-ideas/file-geodatabase-calculate-field-using-sql/idi-p/1279480" target="_self"&gt;File Geodatabase — Calculate field using SQL&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://community.esri.com/t5/arcgis-pro-ideas/file-geodatabase-query-layers/idi-p/1237538" target="_self"&gt;File geodatabase query layers&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://community.esri.com/t5/arcgis-enterprise-ideas/use-sql-for-field-calculations-on-versioned-data/idc-p/1280047#M3271" target="_self"&gt;Use SQL for field calculations on versioned data (option to move edits to base)&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Wed, 19 Apr 2023 13:37:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-a-sql-expression-inside-a-python-or-arcade/m-p/1280050#M67454</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2023-04-19T13:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: Use a SQL expression inside a Python or Arcade field calculation?</title>
      <link>https://community.esri.com/t5/python-questions/use-a-sql-expression-inside-a-python-or-arcade/m-p/1280151#M67458</link>
      <description>&lt;P&gt;Interestingly, SQL &lt;STRONG&gt;is&lt;/STRONG&gt; an option when using the field calculator on a hosted feature service.&lt;/P&gt;&lt;P&gt;For file geodatabase feature classes, I'd recommend taking a look at the "where_clause" and "sql_clause" parameters on the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/updatecursor-class.htm" target="_self"&gt;UpdateCursor&lt;/A&gt;. This might enable your desired workflow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 13:33:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-a-sql-expression-inside-a-python-or-arcade/m-p/1280151#M67458</guid>
      <dc:creator>DannyMcVey</dc:creator>
      <dc:date>2023-04-19T13:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: Use a SQL expression inside a Python or Arcade field calculation?</title>
      <link>https://community.esri.com/t5/python-questions/use-a-sql-expression-inside-a-python-or-arcade/m-p/1280312#M67461</link>
      <description>&lt;P&gt;You could use &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/arcsdesqlexecute.htm" target="_self"&gt;ArcSDESQLExecute&lt;/A&gt; to query your data, format into a dictionary, then use an update cursor or calculate field to update the values by looking them up in your dictionary.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 17:55:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-a-sql-expression-inside-a-python-or-arcade/m-p/1280312#M67461</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2023-04-19T17:55:32Z</dc:date>
    </item>
  </channel>
</rss>

