<?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: Join a Table to a Feature Layer with a Where Clause in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/join-a-table-to-a-feature-layer-with-a-where/m-p/663899#M51581</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In this line of code&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MakeFeatureLayer_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;lyr&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; FeatureLyr&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; dateSearch&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;dateSearch&amp;nbsp;looks to be&amp;nbsp;a where clause, but I don't see where/how it is getting initialized.&amp;nbsp; Are you using something like:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# for file geodatabase&lt;/SPAN&gt;
dateSearch &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"dateField &amp;gt; date '{}'"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;datetime&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;datetime&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;strftime&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;report_time&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"%Y-%m-%d %H:%M:%S"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# result: "dateField = date '2018-01-21 19:01:29'"‍‍‍‍‍‍‍‍‍‍‍‍&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The format of the where clause will vary depending on the database you are using. See &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/map/working-with-layers/sql-reference-for-query-expressions-used-in-arcgis.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;SQL reference for query expressions used in ArcGIS&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 04:04:05 GMT</pubDate>
    <dc:creator>RandyBurton</dc:creator>
    <dc:date>2021-12-12T04:04:05Z</dc:date>
    <item>
      <title>Join a Table to a Feature Layer with a Where Clause</title>
      <link>https://community.esri.com/t5/python-questions/join-a-table-to-a-feature-layer-with-a-where/m-p/663897#M51579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to calculate a field in the feature class from a table. The table and feature class have a common field for a join. I want to filter the feature class to only edit rows that have been edited in the past 7 days. I have created a feature layer with a Where Clause filtering all rows that have been edited in the past 7 days. I am unable to join the table to the feature layer. When I make the feature layer without the where clause the join works and I am able to calculate the field. With the Where Clause in Python I receive an "An invalid SQL statement was used" error. I have also tried each scenario in ArcMap. Without the where clause works but when joining with a feature layer with a Where Clause I receive an error in the join validation:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"The number of matching records for the join:&lt;BR /&gt;- Unexpected error encountered.&lt;BR /&gt;- No matches found by joining"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Has anyone else ran into this problem?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Python code with Where Clause&lt;/P&gt;&lt;P&gt;# Get start and end times for report&lt;BR /&gt;start_time= datetime.timedelta(days = 7)&lt;BR /&gt;end_time = datetime.datetime.now()&lt;BR /&gt;report_time = end_time-start_time #this is the time that gets used to filter records&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Find all records that are later than or = to report_time&lt;BR /&gt;arcpy.MakeFeatureLayer_management(lyr, FeatureLyr, dateSearch)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Join the table to the feature layer and calculate field&lt;BR /&gt;arcpy.AddJoin_management (&lt;SPAN&gt;FeatureLyr&lt;/SPAN&gt;, JoinField, JoinTable, JoinField)&lt;/P&gt;&lt;P&gt;arcpy.CalculateField_management(&lt;SPAN&gt;FeatureLyr&lt;/SPAN&gt;, "TransferField", "!JoinTable.TransferField!", "PYTHON_9.3")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Python code without Where Clause&lt;/P&gt;&lt;P&gt;# Find all records&lt;BR /&gt;arcpy.MakeFeatureLayer_management(lyr, FeatureLyr)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;# Join the table to the feature layer and calculate field&lt;/SPAN&gt;&lt;BR /&gt;arcpy.AddJoin_management (&lt;SPAN&gt;FeatureLyr&lt;/SPAN&gt;, JoinField, JoinTable, JoinField)&lt;/P&gt;&lt;P&gt;arcpy.CalculateField_management(&lt;SPAN&gt;FeatureLyr&lt;/SPAN&gt;, "TransferField", "!JoinTable.TransferField!", "PYTHON_9.3")&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jan 2018 15:56:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/join-a-table-to-a-feature-layer-with-a-where/m-p/663897#M51579</guid>
      <dc:creator>DNVT</dc:creator>
      <dc:date>2018-01-25T15:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: Join a Table to a Feature Layer with a Where Clause</title>
      <link>https://community.esri.com/t5/python-questions/join-a-table-to-a-feature-layer-with-a-where/m-p/663898#M51580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am working in an ArcSDE environment. I have tried other Where Clauses other than a date and it works. When I use a date as my Where Clause I keep receiving the error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ERROR 999999: Error executing function.&lt;/P&gt;&lt;P&gt;An invalid SQL statement was used.&lt;/P&gt;&lt;P&gt;An invalid SQL statement was used.&lt;/P&gt;&lt;P&gt;An invalid SQL statement was used.&lt;/P&gt;&lt;P&gt;An invalid SQL statement was used.&lt;/P&gt;&lt;P&gt;Failed to execute (CalculateField).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Jan 2018 20:39:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/join-a-table-to-a-feature-layer-with-a-where/m-p/663898#M51580</guid>
      <dc:creator>DNVT</dc:creator>
      <dc:date>2018-01-25T20:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: Join a Table to a Feature Layer with a Where Clause</title>
      <link>https://community.esri.com/t5/python-questions/join-a-table-to-a-feature-layer-with-a-where/m-p/663899#M51581</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In this line of code&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;MakeFeatureLayer_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;lyr&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; FeatureLyr&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; dateSearch&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;dateSearch&amp;nbsp;looks to be&amp;nbsp;a where clause, but I don't see where/how it is getting initialized.&amp;nbsp; Are you using something like:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# for file geodatabase&lt;/SPAN&gt;
dateSearch &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"dateField &amp;gt; date '{}'"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;datetime&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;datetime&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;strftime&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;report_time&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"%Y-%m-%d %H:%M:%S"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# result: "dateField = date '2018-01-21 19:01:29'"‍‍‍‍‍‍‍‍‍‍‍‍&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The format of the where clause will vary depending on the database you are using. See &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/map/working-with-layers/sql-reference-for-query-expressions-used-in-arcgis.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;SQL reference for query expressions used in ArcGIS&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:04:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/join-a-table-to-a-feature-layer-with-a-where/m-p/663899#M51581</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2021-12-12T04:04:05Z</dc:date>
    </item>
  </channel>
</rss>

