AnsweredAssumed Answered

Writing IS NULL/IS NOT NULL SQL statements in python/acrpy

Question asked by dorathea on Jun 6, 2019
Latest reply on Jun 10, 2019 by bixb0012

I am trying to write a search cursor that looks through the fields in a Feature Class 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. 


Here is what I have:

import arcpy


inField = 'Prov'  
inField1 = 'Rd_Symbol'
inField2 = 'Name_Type'


nul = 'NULL'
where_clause = inField + " IS " + nul + " or " + inField1 + " IS " + nul + " or " + inField2 + " IS " + nul


with arcpy.da.SearchCursor(inFeature, (inField, inField1, inField2), where_clause) as cursor:
print("NULL values present")

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:


where_clause = 'field_name' is None

where_clause =  'field_name' is 'NULL'

where_clause =  'field_name' IS Null'


but have not had success either getting a syntax error message. Or for 'field_name' is None there was no error message but when I checked the statement this is what I get:

>>>> print(where_clause)


If you have any suggestions or if there is a resource anyone recommends to help better understand writing SQL statements with python/arcpy that would be much appreciated.