2

I am wanting to find features not equal to each other in a feature layer in Python, and I am not finding the right SQL to use. The two features are joined to each other on a MasterID field. When using Select By Attributes query TLNO_GIS <> TLNO, the results are successful. When running the same query in Python (below), the error message returns:

ERROR 000358: Invalid expression ("TLNO_GIS" <> "TLNO") Failed to execute (MakeFeatureLayer).

arcpy.MakeFeatureLayer_management(Production_ISGIS_COH_Address, ISGIS_COH_Address_LayerTaxlot, "(\"TLNO_GIS\" <> \"TLNO\")", "", "OBJECTID OBJECTID VISIBLE NONE;MasterID MasterID VISIBLE NONE;TLNO_GIS TLNO_GIS VISIBLE NONE;TLNO_Taxmap TLNO_Taxmap VISIBLE NONE;TLNO_status TLNO_status VISIBLE NONE;SiteAddress SiteAddress VISIBLE NONE;SitusNum SitusNum VISIBLE NONE;StreetPrefix StreetPrefix VISIBLE NONE;StreetName StreetName VISIBLE NONE;StreetSuffix StreetSuffix VISIBLE NONE;Unit Unit VISIBLE NONE;UnitNum UnitNum VISIBLE NONE;Building Building VISIBLE NONE;BuildingNum BuildingNum VISIBLE NONE;PO_City PO_City VISIBLE NONE;PO_State PO_State VISIBLE NONE;PO_Zip PO_Zip VISIBLE NONE;AddrType AddrType VISIBLE NONE;Description Description VISIBLE NONE;Status Status VISIBLE NONE;AddrJur AddrJur VISIBLE NONE;Office Office VISIBLE NONE;Floor Floor VISIBLE NONE;BuildingID BuildingID VISIBLE NONE;RegionID RegionID VISIBLE NONE;CreateID CreateID VISIBLE NONE;CreateDate CreateDate VISIBLE NONE;Editor Editor VISIBLE NONE;EditDate EditDate VISIBLE NONE;SubPudComplexName SubPudComplexName VISIBLE NONE;PlatLotNum PlatLotNum VISIBLE NONE;PlatRecDate PlatRecDate VISIBLE NONE;X_Coord X_Coord VISIBLE NONE;Y_Coord Y_Coord VISIBLE NONE;Angle Angle VISIBLE NONE;Shape Shape VISIBLE NONE;GlobalID GlobalID VISIBLE NONE;FromSitusNum FromSitusNum VISIBLE NONE;Phase Phase VISIBLE NONE;MasterID MasterID VISIBLE NONE;TLNO TLNO VISIBLE NONE")
4

Don't use the quotes (") around the field names in your where clause.

arcpy.MakeFeatureLayer_management(r'fcname', 'diff_feats', 'OBJECTID <> POLYGON_ID')

Even better, to make your Python script agnostic to the data source used (shapefile, persona/file/SDE geodatabase), use AddFieldDelimiters function for constructing a where clause.

  • That does work if the fields are in the same table, but it does not work with the join from the two different tables. – user73103 Jul 27 '17 at 15:39
  • That's odd. I have added two feature classes from a file geodatabase to a map document. Done join on the cities layer in the TOC (joining states feature class to the cities feature class). Then I run in Python window arcpy.MakeFeatureLayer_management("cities", 'diff_feats', 'state_name <> CITY_NAME'). Hey, make sure both fields are of the same type! – Alex Tereshenkov Jul 27 '17 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy