Testing for Null Values

Discussion created by byoungs32 on Jun 21, 2011
Latest reply on Jun 21, 2011 by csny490

I have a script that is building feature layers based on a SQL expression evaluating an attribute combination.

I am using:
arcpy.MakeFeatureLayer_management(<feature class>, <new layer name>, <whereclause>)

I am trying to find conditions where attribute x is a valid string value (not null, not an empty space, not a placeholder value, etc.) and attribute y is not a valid string value (null, an empty space, etc.).

I can build out an expression in ArcMap and it returns exactly the records I am looking for using:

"[Attribute X] Is Not Null AND [Attribute X] <> "" AND [Attribute X] <> " " AND [Attribute Y] Is Null OR [Attribute Y] =  "" OR [Attribute Y] = " ""

However, when I build that expression to run from the Python script, It will still pull in the records that I am looking for but also some records with null Attribute X values:

"[Attribute X] Is Not Null AND [Attribute X] <> \"\" AND [Attribute X] <> \" \" AND [Attribute Y] Is Null OR [Attribute Y] =  \"\" OR [Attribute Y] = \" \""

It seems like the expression is exactly the same but I am getting different results. Is there a better way to test for null values in an attribute table? Did I screw up the SQL somehow?

Thanks in advance.