<?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: Writing IS NULL/IS NOT NULL SQL statements in python/acrpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5200#M457</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Assuming you are trying to determine&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt; if&amp;nbsp; any value/row in any of the fields are NULL&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;you can try something like:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy

inFeature &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'C:\path\to\file.gdb\SCRIPT_PARAMETER_TEST'&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# path to feature&lt;/SPAN&gt;
fields &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'Prov'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Rd_symbol'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Name_type'&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# create where_clause&lt;/SPAN&gt;
wc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; f &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; fields&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    wc&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'{} IS NULL'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;f&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# search for null fields&lt;/SPAN&gt;
where_clause &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;' OR '&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;wc&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# join to make OR statement&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt; where_clause &lt;SPAN class="comment token"&gt;# print where clause for test&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# Prints: 'Prov IS NULL OR Rd_symbol IS NULL OR Name_type IS NULL'&lt;/SPAN&gt;

rows &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;row &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;inFeature&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; fields&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; where_clause&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; len&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;rows&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# if len(rows) &amp;gt; 0&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'{} has null values'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;inFeature&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'{} does not have null values'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;inFeature&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# but may also be empty feature&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;del&lt;/SPAN&gt; rows‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&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;/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;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;/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;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You could also use &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/select-layer-by-attribute.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Select Layer By Attribute&lt;/A&gt;&amp;nbsp;and &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/get-count.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Get Count&lt;/A&gt;&amp;nbsp;in place of&amp;nbsp;the search cursor (lines 14+).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 20:12:35 GMT</pubDate>
    <dc:creator>RandyBurton</dc:creator>
    <dc:date>2021-12-10T20:12:35Z</dc:date>
    <item>
      <title>Writing IS NULL/IS NOT NULL SQL statements in python/acrpy</title>
      <link>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5192#M449</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to write a search cursor that looks through the fields in a Feature Class&amp;nbsp;and if there is a NULL value in any of the fields prints the statement "NULL values present". I am having trouble getting my where_clause to work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is what I have:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;inFeature = 'SCRIPT_PARAMETERS_TEST'&lt;/P&gt;&lt;P&gt;inField = 'Prov'&amp;nbsp;&amp;nbsp;&lt;BR /&gt;inField1 = 'Rd_Symbol'&lt;BR /&gt;inField2 = 'Name_Type'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;nul = 'NULL'&lt;BR /&gt;where_clause = inField + " IS " + nul + " or " + inField1 + " IS " + nul + " or " + inField2 + " IS " + nul&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with arcpy.da.SearchCursor(inFeature, (inField, inField1, inField2), where_clause) as cursor:&lt;BR /&gt; print("NULL values present")&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The code runs however, there are two problems. First it prints NULL values present always, even when I change the fields to fields that are fully populated. Second I feel like there is probably a cleaner way to write the where clause... I have looked into things like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where_clause = 'field_name' is None&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;where_clause =&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;'field_name' is 'NULL'&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;where_clause =&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;'field_name' IS Null'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but have not had success either getting a syntax error message. Or for 'field_name' is None there was no error&amp;nbsp;message but when I checked the statement this is what I get:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; print(where_clause)&lt;/P&gt;&lt;P&gt;FALSE&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;If you have any suggestions or if there is a resource&amp;nbsp;anyone&amp;nbsp;recommends to help better understand writing SQL statements with python/arcpy that would be much appreciated.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jun 2019 17:29:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5192#M449</guid>
      <dc:creator>DoratheaBlock</dc:creator>
      <dc:date>2019-06-06T17:29:25Z</dc:date>
    </item>
    <item>
      <title>Re: Writing IS NULL/IS NOT NULL SQL statements in python/acrpy</title>
      <link>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5193#M450</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looking over the end of your code:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;inFeature&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;inField&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; inField1&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; inField2&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; where_clause&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"NULL values present"&lt;/SPAN&gt;&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;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Assuming the indentation error is just a copy/paste artifact, where/how are you looping over the cursor?&amp;nbsp; You are creating the cursor and then just printing a single line, and that line will always print if the cursor is instantiated, regardless of how many records are in the cursor.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:12:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5193#M450</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-10T20:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: Writing IS NULL/IS NOT NULL SQL statements in python/acrpy</title>
      <link>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5194#M451</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A better place for this question would be &lt;A href="https://community.esri.com/space/2145"&gt;Python&lt;/A&gt;‌ or &lt;A href="https://community.esri.com/group/1680"&gt;Geodatabase&lt;/A&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Jun 2019 18:02:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5194#M451</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-06-06T18:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: Writing IS NULL/IS NOT NULL SQL statements in python/acrpy</title>
      <link>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5195#M452</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;First it prints NULL values present always, even when I change the fields to fields that are fully populated.&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Could that be a result of using 'OR'?&amp;nbsp; Basically you are asking 'if one or more of these 3 fields is null'.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;I've struggled with where clauses myself: &lt;A _jive_internal="true" href="https://community.esri.com/message/817101-where-clause-in-da-cursor" target="_blank"&gt;in this thread &lt;/A&gt;using field delimeters was suggested and helped immensely.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;In terms of a 'cleaner' where clause, I prefer using the format() function over the use of '+':&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;import arcpy

inFeature = 'SCRIPT_PARAMETERS_TEST'

inField = 'Prov'  
inField1 = 'Rd_Symbol'
inField2 = 'Name_Type'

 

#nul = 'NULL'
#where_clause = inField + " IS " + nul + " or " + inField1 + " IS " + nul + " or " + inField2 + " IS " + nul

where_clause = '{} IS NULL or {} IS NULL or {} IS NULL'.format(inField,inField1,inField2)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&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;/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;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;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:12:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5195#M452</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-12-10T20:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: Writing IS NULL/IS NOT NULL SQL statements in python/acrpy</title>
      <link>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5196#M453</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The&amp;nbsp;quoting of your where clause is incorrect.&amp;nbsp; Try:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;# if field_name is the name of the field:

where_clause = "field_name is NULL"

# if field_name is a variable containing a field name:

field_name = 'myFieldName' # the name of the field

where_clause = "{} is NULL".format(field_name)‍‍‍‍‍‍‍‍‍&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;/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;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That said,&amp;nbsp; I'm not sure if you want to&amp;nbsp;indicate if&amp;nbsp;a feature&amp;nbsp;contains any field&amp;nbsp;where there is a null, or if you want to find rows in the feature that has a field with a null value.&amp;nbsp; See this thread for some additional ideas: &lt;A _jive_internal="true" href="https://community.esri.com/thread/229953-calculate-number-of-null-values-in-a-feature-dataset?commentID=836318#comment" target="_blank"&gt;Calculate number of NULL values in a feature dataset&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:12:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5196#M453</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2021-12-10T20:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: Writing IS NULL/IS NOT NULL SQL statements in python/acrpy</title>
      <link>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5197#M454</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&amp;nbsp;By '&lt;STRONG&gt;Basically you are asking 'if one or more of these 3 fields is null'&lt;/STRONG&gt; &lt;SPAN style="background-color: #ffffff;"&gt;do you mean that I am testing if the field exists or not (that would not be what I am&amp;nbsp;attempting to do)&amp;nbsp;or if&amp;nbsp; any value/row in any of the fields are NULL (what I am trying to do)?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2019 22:46:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5197#M454</guid>
      <dc:creator>DoratheaBlock</dc:creator>
      <dc:date>2019-06-07T22:46:47Z</dc:date>
    </item>
    <item>
      <title>Re: Writing IS NULL/IS NOT NULL SQL statements in python/acrpy</title>
      <link>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5198#M455</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It does seem to be an issue with not looping over the cursor because when I do loop over the cursor the it returns nothing, like I am expecting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;SPAN style="color: #004da8;"&gt;with&lt;/SPAN&gt; arcpy.da.SearchCursor(inFeature, (inField, inField1, inField2), where_clause2) &lt;SPAN style="color: #004da8;"&gt;as&lt;/SPAN&gt; cursor:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #004da8;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for&lt;/SPAN&gt; row &lt;SPAN style="color: #004da8;"&gt;in&lt;/SPAN&gt; cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count+=1&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #004da8;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print&lt;/SPAN&gt;("ANTHOER NULL VALUE")&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #004da8;"&gt;print&lt;/SPAN&gt;(count)&lt;/P&gt;&lt;P&gt;0&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;when I do not loop over the cursor:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;count = 0&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #004da8;"&gt;with&lt;/SPAN&gt; arcpy.da.SearchCursor(inFeature, (inField, inField1, inField2), where_clause2) &lt;SPAN style="color: #004da8;"&gt;as&lt;/SPAN&gt; cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count+=1 # indentation is 2x Tab&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #004da8;"&gt;&lt;SPAN style="color: #3d3d3d;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;print&lt;/SPAN&gt;("ANTHOER NULL VALUE")&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #004da8;"&gt;print&lt;/SPAN&gt;(count)&lt;/P&gt;&lt;P&gt;ANTHOER NULL VALUE&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; count = 0&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #004da8;"&gt;with&lt;/SPAN&gt; arcpy.da.SearchCursor(inFeature, (inField, inField1, inField2), where_clause2) &lt;SPAN style="color: #004da8;"&gt;as&lt;/SPAN&gt; cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; count+=1 ## indentation is 1x Tab&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #004da8;"&gt;print&lt;/SPAN&gt;("ANOTHER NULL VALUE")&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #004da8;"&gt;print&lt;/SPAN&gt;(count)&lt;/P&gt;&lt;P&gt;ANOTHER NULL VALUE&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was under the impression that you didn't have to loop over a cursor for it to work but maybe I was misinformed... Do you always loop over a cursor?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2019 23:17:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5198#M455</guid>
      <dc:creator>DoratheaBlock</dc:creator>
      <dc:date>2019-06-07T23:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: Writing IS NULL/IS NOT NULL SQL statements in python/acrpy</title>
      <link>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5199#M456</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The latter. You know the fields exist;&amp;nbsp; you are checking the values. What I am suggesting is sometimes we need to be careful for what we ask for.&amp;nbsp; &amp;nbsp;With the OR&amp;nbsp; condition all you need is one of those three fields to be the &amp;lt;Null&amp;gt; value (None in pythonese) and your Where statement evaluates to true.&amp;nbsp; &amp;nbsp;I think you and &lt;A href="https://community.esri.com/migrated-users/3420"&gt;Joshua Bixby&lt;/A&gt;‌ have a good thing going. I'll watch from sidelines...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Jun 2019 02:18:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5199#M456</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2019-06-08T02:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: Writing IS NULL/IS NOT NULL SQL statements in python/acrpy</title>
      <link>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5200#M457</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Assuming you are trying to determine&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt; if&amp;nbsp; any value/row in any of the fields are NULL&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;you can try something like:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy

inFeature &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'C:\path\to\file.gdb\SCRIPT_PARAMETER_TEST'&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# path to feature&lt;/SPAN&gt;
fields &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'Prov'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Rd_symbol'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Name_type'&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# create where_clause&lt;/SPAN&gt;
wc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; f &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; fields&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    wc&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'{} IS NULL'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;f&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# search for null fields&lt;/SPAN&gt;
where_clause &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;' OR '&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;wc&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# join to make OR statement&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt; where_clause &lt;SPAN class="comment token"&gt;# print where clause for test&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# Prints: 'Prov IS NULL OR Rd_symbol IS NULL OR Name_type IS NULL'&lt;/SPAN&gt;

rows &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;row &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;inFeature&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; fields&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; where_clause&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; len&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;rows&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# if len(rows) &amp;gt; 0&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'{} has null values'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;inFeature&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'{} does not have null values'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;inFeature&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# but may also be empty feature&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;del&lt;/SPAN&gt; rows‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&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;/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;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;/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;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You could also use &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/select-layer-by-attribute.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Select Layer By Attribute&lt;/A&gt;&amp;nbsp;and &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/get-count.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Get Count&lt;/A&gt;&amp;nbsp;in place of&amp;nbsp;the search cursor (lines 14+).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:12:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5200#M457</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2021-12-10T20:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: Writing IS NULL/IS NOT NULL SQL statements in python/acrpy</title>
      <link>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5201#M458</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/4422"&gt;Joe Borgione&lt;/A&gt;‌, I am tied up with family the next couple days, feel free to chime in.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jun 2019 13:45:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5201#M458</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-06-10T13:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: Writing IS NULL/IS NOT NULL SQL statements in python/acrpy</title>
      <link>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5202#M459</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As Joe already mentioned, you have to loop over a cursor to do anything with it.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Revisiting the first statement of your original post:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;I am trying to write a search cursor that looks through the fields in a Feature Class&amp;nbsp;and if there is a NULL value in any of the fields prints the statement "NULL values present".&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Another approach would be to do it all in Python:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy

fc &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# path to feature class&lt;/SPAN&gt;
flds &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# list of fields to check for NULL&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SearchCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fc&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"OID@"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; flds&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; cur&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; cur&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; None &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; row&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
            &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;row&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;/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;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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:12:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-is-null-is-not-null-sql-statements-in/m-p/5202#M459</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-10T20:12:38Z</dc:date>
    </item>
  </channel>
</rss>

