<?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 Where Clause is being ignored in MakeTableView in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/where-clause-is-being-ignored-in-maketableview/m-p/1336796#M68941</link>
    <description>&lt;P&gt;In a standalone script, I am trying to use arcpy.MakeTableView_management().&amp;nbsp; I'm including a "where clause" in the parameters in order to include only certain records in the resulting Table View.&amp;nbsp; With the ArcMap arcpy runtime, it worked, but with Pro, the "where clause" gets ignored - it has no effect.&amp;nbsp; It doesn't throw an error; the script just runs into trouble later on because it is trying to work with records that it's not designed to work with.&lt;/P&gt;&lt;P&gt;I have tried a variety of different where clauses that target a variety of fields in the source table.&amp;nbsp; None have an effect.&amp;nbsp; I tried manually doing Select by Attributes in Pro (rather than in the script), and that worked fine.&amp;nbsp; I even copied the SQL from the Pro Select by Attributes GUI into my script, but still it had no effect.&lt;/P&gt;&lt;P&gt;I can probably come up with a workaround, but this function should work!&amp;nbsp; Or at least I'd like to know why it isn't working.&lt;/P&gt;&lt;P&gt;The input table is a SQL Server database table, not from any kind of geodatabase.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are the relevant lines:&amp;nbsp; (of course my script uses the real names, and bus_lic_tv is used later in the script)&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
arcpy.env.workspace = r"C:\Path\to\Geodatabase.gdb"
table_data = r"C:\Users\adailey\AppData\Roaming\Esri\ArcGISPro\Favorites\DatabaseName.sde\Database.dbo.TableName"
bus_lic_tv = arcpy.MakeTableView_management(table_data, "bus_lic_no_null_apns", where_clause='APN IS NOT NULL')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Does anyone know why the "where clause" is being ignored??&amp;nbsp; Thank you!&lt;/P&gt;</description>
    <pubDate>Wed, 11 Oct 2023 00:23:51 GMT</pubDate>
    <dc:creator>AllenDailey1</dc:creator>
    <dc:date>2023-10-11T00:23:51Z</dc:date>
    <item>
      <title>Where Clause is being ignored in MakeTableView</title>
      <link>https://community.esri.com/t5/python-questions/where-clause-is-being-ignored-in-maketableview/m-p/1336796#M68941</link>
      <description>&lt;P&gt;In a standalone script, I am trying to use arcpy.MakeTableView_management().&amp;nbsp; I'm including a "where clause" in the parameters in order to include only certain records in the resulting Table View.&amp;nbsp; With the ArcMap arcpy runtime, it worked, but with Pro, the "where clause" gets ignored - it has no effect.&amp;nbsp; It doesn't throw an error; the script just runs into trouble later on because it is trying to work with records that it's not designed to work with.&lt;/P&gt;&lt;P&gt;I have tried a variety of different where clauses that target a variety of fields in the source table.&amp;nbsp; None have an effect.&amp;nbsp; I tried manually doing Select by Attributes in Pro (rather than in the script), and that worked fine.&amp;nbsp; I even copied the SQL from the Pro Select by Attributes GUI into my script, but still it had no effect.&lt;/P&gt;&lt;P&gt;I can probably come up with a workaround, but this function should work!&amp;nbsp; Or at least I'd like to know why it isn't working.&lt;/P&gt;&lt;P&gt;The input table is a SQL Server database table, not from any kind of geodatabase.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are the relevant lines:&amp;nbsp; (of course my script uses the real names, and bus_lic_tv is used later in the script)&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
arcpy.env.workspace = r"C:\Path\to\Geodatabase.gdb"
table_data = r"C:\Users\adailey\AppData\Roaming\Esri\ArcGISPro\Favorites\DatabaseName.sde\Database.dbo.TableName"
bus_lic_tv = arcpy.MakeTableView_management(table_data, "bus_lic_no_null_apns", where_clause='APN IS NOT NULL')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Does anyone know why the "where clause" is being ignored??&amp;nbsp; Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2023 00:23:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-clause-is-being-ignored-in-maketableview/m-p/1336796#M68941</guid>
      <dc:creator>AllenDailey1</dc:creator>
      <dc:date>2023-10-11T00:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Where Clause is being ignored in MakeTableView</title>
      <link>https://community.esri.com/t5/python-questions/where-clause-is-being-ignored-in-maketableview/m-p/1336863#M68942</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/206981"&gt;@AllenDailey1&lt;/a&gt;&amp;nbsp;,&amp;nbsp; I think your Make Table View statement should look like this :&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;bus_lic_tv = arcpy.MakeTableView_management(table_data, "bus_lic_no_null_apns","APN IS NOT NULL")&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;- without the &lt;EM&gt;where_clause=&lt;/EM&gt; part&lt;/P&gt;&lt;P&gt;- use double quotes &lt;EM&gt;""&lt;/EM&gt; around the where clause.&lt;/P&gt;&lt;P&gt;It works for me with that syntax.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2023 09:50:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-clause-is-being-ignored-in-maketableview/m-p/1336863#M68942</guid>
      <dc:creator>ChrisUnderwood</dc:creator>
      <dc:date>2023-10-11T09:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: Where Clause is being ignored in MakeTableView</title>
      <link>https://community.esri.com/t5/python-questions/where-clause-is-being-ignored-in-maketableview/m-p/1337143#M68944</link>
      <description>&lt;P&gt;Thank you very much for your suggestion!&lt;/P&gt;&lt;P&gt;I tried your suggestions, and sadly, the "where clause" is still being ignored.&amp;nbsp; So weird.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2023 22:18:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-clause-is-being-ignored-in-maketableview/m-p/1337143#M68944</guid>
      <dc:creator>AllenDailey1</dc:creator>
      <dc:date>2023-10-11T22:18:46Z</dc:date>
    </item>
    <item>
      <title>Re: Where Clause is being ignored in MakeTableView</title>
      <link>https://community.esri.com/t5/python-questions/where-clause-is-being-ignored-in-maketableview/m-p/1337244#M68945</link>
      <description>&lt;P&gt;Where and how are you checking your&amp;nbsp;&lt;EM&gt;bus_lic_no_null_apns&lt;/EM&gt; View, to see that the "where clause" is being ignored ?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2023 12:40:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-clause-is-being-ignored-in-maketableview/m-p/1337244#M68945</guid>
      <dc:creator>ChrisUnderwood</dc:creator>
      <dc:date>2023-10-12T12:40:47Z</dc:date>
    </item>
    <item>
      <title>Re: Where Clause is being ignored in MakeTableView</title>
      <link>https://community.esri.com/t5/python-questions/where-clause-is-being-ignored-in-maketableview/m-p/1337319#M68948</link>
      <description>&lt;P&gt;Later in the script, data from the table view is manipulated - hyphens are inserted between the numbers in the field "APN".&amp;nbsp; This throws an error, because that action can't be done on Nulls.&amp;nbsp; So that means the records where APN is null were mistakenly included in the table view (meaning the Where Clause was ignored).&amp;nbsp; For troubleshooting, I also included a print statement that prints out the APN's of the records included in the table view - print("APN is " + APN).&amp;nbsp; For the records that have a value in the APN field, it prints, but for other records it errors out, saying it can't concatenate string and NoneType.&lt;BR /&gt;&lt;BR /&gt;For troubleshooting, I tried running MakeTableView, including a Where Clause, on a geodatabase feature class rather than a SQL Server database table (which was the original data format I was running it on), and the Where Clause worked!&amp;nbsp; So now my theory is that the problem is the data table type.&amp;nbsp; Maybe I will try adding code to my script to first convert the database table into a geodatabase table or something, before doing MakeTableView.&amp;nbsp; That would defeat the purpose of having intermediate products just be in memory, but that could be okay.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2023 15:34:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-clause-is-being-ignored-in-maketableview/m-p/1337319#M68948</guid>
      <dc:creator>AllenDailey1</dc:creator>
      <dc:date>2023-10-12T15:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: Where Clause is being ignored in MakeTableView</title>
      <link>https://community.esri.com/t5/python-questions/where-clause-is-being-ignored-in-maketableview/m-p/1338945#M68981</link>
      <description>&lt;P&gt;I came up with a workaround.&amp;nbsp; Instead of using a "where clause," I just added an "if" statement later in the script to exclude records that would have been excluded by the "where clause." Basically, within a Search Cursor, I put lines to this effect:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.SearchCursor(fc, fields) as cursor:
    for row in cursor:
        # Only include records where APN exists:
        if row[0]:  # row[0] is the APN
            # then do stuff&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works, but it would be less clunky to just be able to use a "where clause" in MakeTableView.&amp;nbsp; I'd still be very interested to find out why it doesn't seem to work with the type of table I'm using.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2023 23:19:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-clause-is-being-ignored-in-maketableview/m-p/1338945#M68981</guid>
      <dc:creator>AllenDailey1</dc:creator>
      <dc:date>2023-10-17T23:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Where Clause is being ignored in MakeTableView</title>
      <link>https://community.esri.com/t5/python-questions/where-clause-is-being-ignored-in-maketableview/m-p/1340144#M69011</link>
      <description>&lt;P&gt;Have you tried&amp;nbsp;"NOT APN IS NULL" or may need&amp;nbsp;"NOT (APN IS NULL)" but I think I remember what you had will not work.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 18:12:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-clause-is-being-ignored-in-maketableview/m-p/1340144#M69011</guid>
      <dc:creator>DougBrowning</dc:creator>
      <dc:date>2023-10-20T18:12:40Z</dc:date>
    </item>
  </channel>
</rss>

