<?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: Using the same table view with and without a join throws an error when using SelectLayerByAttribute in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449959#M35252</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I suggest double quotes for around those long, gnarly SDE table name prefixes.&lt;/P&gt;&lt;P&gt;(I'm using \" to embed them below.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Forgive me editing your posts, but they were being cut off so we couldn't see the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.SelectLayerByAttribute_management("missu_lyr","NEW_SELECTION",(&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; "\"RockGIS.DPWUTIL.MissUtilityTickets_TEST.TicketStatus\" = 'Marked' OR "&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; "\"RockGIS.DPWUTIL.MissUtilityTickets_TEST.TicketStatus\" = 'Clear/No conflict'"))&amp;nbsp; &lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW Python string formatting is your friend with messy expressions like this, also you can use IN to simplify things:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fld = '"RockGIS.DPWUTIL.MissUtilityTickets_TEST.TicketStatus"'
where = "{} IN ('Marked', 'Clear/No conflict')".format(fld)
arcpy.SelectLayerByAttribute_management("missu_lyr", "", where)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 20:05:15 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2021-12-11T20:05:15Z</dc:date>
    <item>
      <title>Using the same table view with and without a join throws an error when using SelectLayerByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449944#M35237</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've been working on a python script for awhile now and I've been stumped for over a week as to why the script would throw an error when I tried to use SelectLayerByAttribute after I removed a join on a tableview that is based on a SDE featureclass.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I finally figured out the solution today but I don't really understand why it works. Or, I should say, I don't understand why it didn't work before.&amp;nbsp; The solution was to break my script into two parts: Using one view for the AddJoin and then &lt;STRONG&gt;deleting&lt;/STRONG&gt; that view and &lt;STRONG&gt;creating&lt;/STRONG&gt; a separate view to perform an action without the join.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I had a working script that created a tableview using a where clause from an SDE featureclass, pulled in data from other sources, joined that data to the tableview, did some calculations, then removed the join and deleted the tableview.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.MakeTableView_management(os.path.join(wksp, targetFC),"missu_lyr",where_clause = "OpenClosed = 'O' OR OpenClosed IS NULL", workspace="")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Later on I needed to do an additional calculation on the featureclass but I didn't need the table joined anymore. I tried to just continue my workflow by removing that join and using the SelectLayerByAttribute command to get a subset and then calculate the values. However, I kept getting an "ERROR 000358: Invalid expression" on it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.AddJoin_management(in_layer_or_view="missu_lyr", in_field="TicketNo", join_table=path_to_table, join_field="TicketNo", join_type="KEEP_COMMON")
# do stuff
arcpy.RemoveJoin_management('missu_lyr')
arcpy.SelectLayerByAttribute_management("missu_lyr","NEW_SELECTION","TicketStatus = 'Marked' ")&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;EM&gt;Executing: SelectLayerByAttribute missu_lyr NEW_SELECTION " "TicketStatus" =&amp;nbsp; 'Marked'"&lt;/EM&gt;
&lt;EM&gt;Start Time: Mon Oct 12 17:30:07 2015&lt;/EM&gt;
&lt;EM&gt;ERROR 000358: Invalid expression&lt;/EM&gt;
&lt;EM&gt;An invalid SQL statement was used.&lt;/EM&gt;
&lt;EM&gt;Failed to execute (SelectLayerByAttribute).&lt;/EM&gt;&lt;/PRE&gt;&lt;P&gt;What really stumped me is that I could run my script to a certain point (I'm using PyScripter) and then try the select command and check the results with GetCount_management and I get what expected. I also did the workflow in the interactive window in ArcMap with no errors.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After 37 minutes on the phone with ESRI tech support today I could not give up (they were elevating my issue) and I finally tried removing the join, deleting the view and recreating a new view with a new name and the same syntax.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.MakeTableView_management(os.path.join(wksp, targetFC),"missu_lyr2",where_clause = "OpenClosed = 'O' OR OpenClosed IS NULL", workspace="")
arcpy.SelectLayerByAttribute_management("missu_lyr2","NEW_SELECTION","TicketStatus = 'Marked' ")&lt;/PRE&gt;&lt;P&gt;Then the selection worked. The calculation worked. My script finally worked.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does the act of creating a join and then removing it leave some funny prefixed fieldname behind? Or is it a best practice to always create a new view after a join before doing selections?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Mike Onzay

Edited to add syntax highlighting&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:05:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449944#M35237</guid>
      <dc:creator>MikeOnzay</dc:creator>
      <dc:date>2021-12-11T20:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using the same table view with and without a join throws an error when using SelectLayerByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449945#M35238</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am curious whether you actually kill the link to the previous view in your script by deleting references to it at the end of your first process?&amp;nbsp; It appears that it is floating around in some state after the first, which causes issues as you move forward.&amp;nbsp; I have experienced similar pecularities with 'things' in Arcmap if a script tool fails between successive runs since remnants remain in memory.&amp;nbsp; I find it useful to maintain a commented line in my scripts that contains the locals().keys() of variables that I create so I can delete them fully at the completion of a script or to be used uncommented should a script fail.&lt;/P&gt;&lt;P&gt;​&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Oct 2015 03:29:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449945#M35238</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-10-13T03:29:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using the same table view with and without a join throws an error when using SelectLayerByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449946#M35239</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you removing or clearing the selection before removing the join?&amp;nbsp; If you make a selection against a Feature Layer or Table View and don't clear it before breaking a join, it seems to hang onto references of the join after you try to remove it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Oct 2015 13:48:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449946#M35239</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-10-13T13:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using the same table view with and without a join throws an error when using SelectLayerByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449947#M35240</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In the first part of my script the view is created with a where clause which I think is like a selection but not something you can really clear. Then I do the join. Then some calculations. Initially I was trying to do a new selection on that view and it was failing even after removing the join. My scenario is a little different from what you are asking although I don't disagree with it. In some earlier versions of my script when I was trying to figure out the correct workflow (I had more selections in the second part) I was intentionally clearing the selections.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Oct 2015 14:00:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449947#M35240</guid>
      <dc:creator>MikeOnzay</dc:creator>
      <dc:date>2015-10-13T14:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using the same table view with and without a join throws an error when using SelectLayerByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449948#M35241</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;All I know how to do is use &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.Delete_management('missu_lyr') &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to delete that view. I'm not aware that I can do anything else. Your suggestion of keeping track of locals().keys() is something new for me that I will explore.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think my approach of creating a new view to do selections is reasonable. I'm not processing large files so I'm not worried about running out of memory before the script ends&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Oct 2015 14:11:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449948#M35241</guid>
      <dc:creator>MikeOnzay</dc:creator>
      <dc:date>2015-10-13T14:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using the same table view with and without a join throws an error when using SelectLayerByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449949#M35242</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;let's assume that you have a variable in your script that references an object&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;my_variable = "missu_lyr"&amp;nbsp; # where missu_lyr is a layer in ArcMap&lt;/P&gt;&lt;P&gt;...blah do stuff&lt;/P&gt;&lt;P&gt;...do more&lt;/P&gt;&lt;P&gt;... done&lt;/P&gt;&lt;P&gt;arcpy.Delete_management('missu_lyr')&lt;/P&gt;&lt;P&gt;del my_variable&amp;nbsp;&amp;nbsp; # Add this line... just a shot just in case the variable is still referencing the layer&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Oct 2015 14:15:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449949#M35242</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-10-13T14:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using the same table view with and without a join throws an error when using SelectLayerByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449950#M35243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you saying that rather than just using arcpy.MakeTableview by itself it would be better to call it while it is being assigned to a variable?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did a test.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;myvar = arcpy.MakeTableView_management(os.path.join(wksp, targetFC),"missu_lyr",where_clause = "OpenClosed = 'O' OR OpenClosed IS NULL", workspace="")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.GetCount_management("missu_lyr")
&amp;lt;Result '27'&amp;gt;
arcpy.Delete_management('missu_lyr', 'GPTableView')
&amp;lt;Result 'true'&amp;gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;myvar
&amp;lt;Result 'missu_lyr'&amp;gt;&lt;/PRE&gt;&lt;P&gt;# I did not expect to see this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.GetCount_management("missu_lyr")

Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;interactive input&amp;gt;", line 1, in &amp;lt;module&amp;gt;
&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\management.py", line 15306, in GetCount
&amp;nbsp;&amp;nbsp;&amp;nbsp; raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Rows: Dataset missu_lyr does not exist or is not supported
Failed to execute (GetCount).&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did it the other way too.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;myvar = arcpy.MakeTableView_management(os.path.join(wksp, targetFC),"missu_lyr",where_clause = "OpenClosed = 'O' OR OpenClosed IS NULL", workspace="")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.GetCount_management("missu_lyr")
&amp;lt;Result '27'&amp;gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;del myvar
arcpy.GetCount_management("missu_lyr")
&amp;lt;Result '27'&amp;gt;&lt;/PRE&gt;&lt;P&gt;Maybe this is a case where the variable is just referencing the object and not actually holding it? Deleting the variable just deletes the reference.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:05:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449950#M35243</guid>
      <dc:creator>MikeOnzay</dc:creator>
      <dc:date>2021-12-11T20:05:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using the same table view with and without a join throws an error when using SelectLayerByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449951#M35244</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My response here is mostly an aside to the original dialogue, but there are a couple of things I think are worth bringing up.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, it is helpful to format your code or use syntax highlighting.&amp;nbsp; There are numerous blog posts and comments about how to do it.&amp;nbsp; A good place to start is &lt;A href="https://community.esri.com/migrated-users/3355" target="_blank"&gt;Curtis Price&lt;/A&gt;​'s blog post, &lt;A href="https://community.esri.com/migration-blogpost/1070" target="_blank"&gt;Posting Code blocks in the new GeoNet&lt;/A&gt;​.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Second, most, if not all, ArcGIS geoprocessing tools return a &lt;A href="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-classes/result.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Result &lt;/A&gt;object.&amp;nbsp; The interactive Python window hints at that fact by showing &lt;SPAN style="font-family: courier new,courier;"&gt;&amp;lt;Result '27'&amp;gt;&lt;/SPAN&gt; in the window when you run the Get Count tool in your test.&amp;nbsp; Looking at an example might be helpful:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; tmpTable = arcpy.CreateTable_management('in_memory','temp')
&amp;gt;&amp;gt;&amp;gt; type(tmpTable)
&amp;lt;class 'arcpy.arcobjects.arcobjects.Result'&amp;gt;
&amp;gt;&amp;gt;&amp;gt; tmpTable.__repr__()
"&amp;lt;Result 'in_memory\\\\temp'&amp;gt;"
&amp;gt;&amp;gt;&amp;gt; tmpTable.__str__()
'in_memory\\temp'
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you can see with line #2-3, the Create Table tool returns a &lt;A href="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-classes/result.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Result &lt;/A&gt;object.&amp;nbsp; The Result object's representation, via the representation dunder method (&lt;A href="https://docs.python.org/2/reference/datamodel.html#basic-customization" rel="nofollow noopener noreferrer" target="_blank"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;object.__repr__&lt;/SPAN&gt;&lt;/A&gt;), is what users are used to seeing in the interactive Python window (line #5).&amp;nbsp; Whereas the __repr__ method is the “official” string representation of an object, the __str__ method (&lt;A href="https://docs.python.org/2/reference/datamodel.html#basic-customization" rel="nofollow noopener noreferrer" target="_blank"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;object.__str__&lt;/SPAN&gt;&lt;/A&gt;) is the “informal” string representation of an object, which is what geoprocessing tools are using to determine the path to objects and what not when a Result object from one tool is passed to another tool.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I mention the above because using the built-in Python delete function won't delete the object being referenced by the Result object.&amp;nbsp; To delete ArcPy/ArcGIS objects, you should use the &lt;A href="http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/delete.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Delete tool &lt;/A&gt;first and then you can delete the variable referencing the result object if you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.Delete_management(tmpTable)
&amp;lt;Result 'true'&amp;gt;
&amp;gt;&amp;gt;&amp;gt; tmpTable
&amp;lt;Result 'in_memory\\temp'&amp;gt;
&amp;gt;&amp;gt;&amp;gt; del tmpTable
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:05:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449951#M35244</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T20:05:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using the same table view with and without a join throws an error when using SelectLayerByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449952#M35245</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the link on how to post code because I know that I'm supposed to do that but it was not obvious to me last night as to where I could find it on the editor toolbar.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Oct 2015 17:24:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449952#M35245</guid>
      <dc:creator>MikeOnzay</dc:creator>
      <dc:date>2015-10-13T17:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using the same table view with and without a join throws an error when using SelectLayerByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449953#M35246</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you post more complete code?&amp;nbsp; You mention doing some "calculations," what calculations specifically before trying to remove the join.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Oct 2015 16:47:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449953#M35246</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-10-14T16:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: Using the same table view with and without a join throws an error when using SelectLayerByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449954#M35247</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Read this post briefly and think this knowledge base article may be of some use:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.esri.com/en/knowledgebase/techarticles/detail/44214" title="http://support.esri.com/en/knowledgebase/techarticles/detail/44214"&gt;44214 - Why is the del statement in Python unable to delete data referenced by variables?&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Oct 2015 17:47:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449954#M35247</guid>
      <dc:creator>AlexanderNohe1</dc:creator>
      <dc:date>2015-10-14T17:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using the same table view with and without a join throws an error when using SelectLayerByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449955#M35248</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Alexander even though &lt;STRONG&gt;del&lt;/STRONG&gt; obviously can't be used to delete data (I am not sure that was implied anywhere) but I also assuming &lt;STRONG&gt;del&lt;/STRONG&gt; wouldn't remove arcmap locks on data either, but lets just lets python go on its way leaving arcmap oblivious to it (?!).&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Oct 2015 18:47:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449955#M35248</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-10-14T18:47:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using the same table view with and without a join throws an error when using SelectLayerByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449956#M35249</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The script builds a table in a file gdb using other data sources. That table is is joined to the SDE featureclass and then 4 fields in the FC are calculated. In the code below I'm only showing the first of the 4 fields that gets calculated from the join table. The second calculate in row 3 below doesn't use any value from the join table but I need to calculate this value now while the tables are joined.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.AddJoin_management(in_layer_or_view="missu_lyr", in_field="TicketNo", join_table=path_to_join_table, join_field="TicketNo", join_type="KEEP_COMMON")&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;with arcpy.da.Editor(wksp) as edit:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management('missu_lyr', sdeFieldPrefix + 'TicketStatus',"!ticketstatus.TicketStatus!",expression_type="PYTHON_9.3",code_block="#")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management('missu_lyr', sdeFieldPrefix + 'OpenClosed','"O"',expression_type="PYTHON_9.3",code_block="#")&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.RemoveJoin_management('missu_lyr')&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At this point missu_lyr is still a subset (the subset being that the where_clause when the view was setup had: where_clause = "OpenClosed = 'O' OR OpenClosed IS NULL") of the the entire data without the join now. I just found that if I tried to do a new selection on it&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.SelectLayerByAttribute_management("missu_lyr","NEW_SELECTION","TicketStatus = 'Marked' OR TicketStatus = 'Clear/No conflict'")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the selection failed. It was only after deleting the view and creating a new view did the selection work. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:05:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449956#M35249</guid>
      <dc:creator>MikeOnzay</dc:creator>
      <dc:date>2021-12-11T20:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using the same table view with and without a join throws an error when using SelectLayerByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449957#M35250</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;After you remove the join, check the field list to see if it is messed up.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14449223795773554 jive_text_macro" data-renderedposition="50_8_912_16" jivemacro_uid="_14449223795773554" modifiedtitle="true"&gt;&lt;P&gt;print([f.name for f in arcpy.ListFields("missu_lyr")])&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It does sound like you could have a bug there. If you get an answer from Esri support please add it to the thread.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Oct 2015 15:18:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449957#M35250</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2015-10-15T15:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using the same table view with and without a join throws an error when using SelectLayerByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449958#M35251</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Before the join the fields look like this:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;u'TicketStatus'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;During the join all of the fields look like:&lt;BR /&gt; &lt;SPAN style="font-family: courier new,courier;"&gt;u'RockGIS.DPWUTIL.MissUtilityTickets_TEST.TicketStatus'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.SelectLayerByAttribute_management("missu_lyr","NEW_SELECTION",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "TicketStatus = 'Marked' OR TicketStatus = 'Clear/No conflict'")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.SelectLayerByAttribute_management("missu_lyr","NEW_SELECTION",(
&amp;nbsp;&amp;nbsp;&amp;nbsp; "RockGIS.DPWUTIL.MissUtilityTickets_TEST.TicketStatus = 'Marked' OR"
&amp;nbsp;&amp;nbsp;&amp;nbsp; "RockGIS.DPWUTIL.MissUtilityTickets_TEST.TicketStatus = 'Clear/No conflict'"))&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;throw ExecuteError: ERROR 000358: Invalid expression&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I remove the join the fields look like this: u'TicketStatus'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The selection still doesn't not work. I have to delete the view and create a new one and then the selection will work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:05:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449958#M35251</guid>
      <dc:creator>MikeOnzay</dc:creator>
      <dc:date>2021-12-11T20:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using the same table view with and without a join throws an error when using SelectLayerByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449959#M35252</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I suggest double quotes for around those long, gnarly SDE table name prefixes.&lt;/P&gt;&lt;P&gt;(I'm using \" to embed them below.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Forgive me editing your posts, but they were being cut off so we couldn't see the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.SelectLayerByAttribute_management("missu_lyr","NEW_SELECTION",(&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; "\"RockGIS.DPWUTIL.MissUtilityTickets_TEST.TicketStatus\" = 'Marked' OR "&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; "\"RockGIS.DPWUTIL.MissUtilityTickets_TEST.TicketStatus\" = 'Clear/No conflict'"))&amp;nbsp; &lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW Python string formatting is your friend with messy expressions like this, also you can use IN to simplify things:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fld = '"RockGIS.DPWUTIL.MissUtilityTickets_TEST.TicketStatus"'
where = "{} IN ('Marked', 'Clear/No conflict')".format(fld)
arcpy.SelectLayerByAttribute_management("missu_lyr", "", where)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:05:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449959#M35252</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T20:05:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using the same table view with and without a join throws an error when using SelectLayerByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449960#M35253</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;After working with ESRI tech support on this for the last few weeks I'm answering my original question / discussion by stating that ESRI agrees that removing the join should have not caused the subsequent use of SelectByLayerAttribute to fail.&amp;nbsp; It is a bug and they were able to reproduce the error I was seeing using their own test data. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="font-size: 10.0pt; font-family: 'Arial',sans-serif;"&gt;BUG-000091905 : If an "OR" operator is specified on a table view and that table view previously participated in a join, running the Select by Attributes geoprocessing tool encounters error 000358: Invalid expression&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Arial',sans-serif;"&gt;In working with &lt;STRONG&gt;MY&lt;/STRONG&gt; case, ESRI determined that using the IN operator instead of an OR would be a workaround. I can confirm that this works. However, using &lt;STRONG&gt;IN&lt;/STRONG&gt; may not work in all cases.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Arial',sans-serif;"&gt;In researching this error ESRI also found a similar bug &lt;A href="http://support.esri.com/en/bugs/nimbus/TklNMDk3NjM0" title="http://support.esri.com/en/bugs/nimbus/TklNMDk3NjM0"&gt;NIM097634 - The Select Layer By Attribute where_clause tool fa..&lt;/A&gt; that was found in 2013 and is still open.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Arial',sans-serif;"&gt;Hopefully this new bug will help both bugs rise to the top and get fixed soon.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Nov 2015 21:26:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449960#M35253</guid>
      <dc:creator>MikeOnzay</dc:creator>
      <dc:date>2015-11-04T21:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: Using the same table view with and without a join throws an error when using SelectLayerByAttribute</title>
      <link>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449961#M35254</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/11339"&gt;Mike Onzay&lt;/A&gt;​, thanks for the follow up, much appreciated.&amp;nbsp; In your case, I am glad there is a workaround, but I always have to shake my head when those 2+ year old bugs that are still open rear their ugly heads.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Nov 2015 21:37:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-the-same-table-view-with-and-without-a-join/m-p/449961#M35254</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-11-04T21:37:16Z</dc:date>
    </item>
  </channel>
</rss>

