jread

Table join on SDE FC in Python?

Discussion created by jread on Jan 4, 2012
Latest reply on Jan 4, 2012 by jread
I am simply trying to join a table from an SDE featureclass to another table, then calculate some field values after the join.  It is a very simple process, and relatively easy to do in ArcMap itself, but I'm having a really hard time getting it to work in Python.  Apparently AddJoin_management will not work for SDE FCs, so what options are there?

# Import arcpy module
import arcpy

# Local variables:
AUSTIN_WWManhole = "Database Connections\\wwwgisoraold.sde\\AUSTIN.AustinWastewater\\AUSTIN.WWManhole"
IMSV7_COMPSMH = "Database Connections\\Hansen_Tables_Production.odc\\IMSV7.COMPSMH"

# Join tables based on COMPKEY field, only keep matching records
arcpy.AddJoin_management(AUSTIN_WWManhole, "COMPKEY", IMSV7_COMPSMH, "COMPKEY", "KEEP_COMMON")

# Select records where METERED = 'Y'
arcpy.SelectLayerByAttribute_management(AUSTIN_WWManhole, "NEW_SELECTION", "\"IMSV7.METERED\" = 'Y'")

# Calculate METERINDICATOR = "Y" for selected records
arcpy.CalculateField_management(AUSTIN_WWManhole, "AUSTIN.WWManhole.METERINDICATOR", "\"Y\"", "PYTHON_9.3", "")

# Select records where METERED = 'N' and METERINDICATOR = 'Y'
arcpy.SelectLayerByAttribute_management(AUSTIN_WWManhole, "NEW_SELECTION", "\"IMSV7.METERED\" = 'N' AND AUSTIN.WWManhole.METERINDICATOR = 'Y'")

# Calculate METERINDICATOR = "N" for selected records
arcpy.CalculateField_management(AUSTIN_WWManhole, "AUSTIN.WWManhole.METERINDICATOR", "\"N\"", "PYTHON_9.3", "")

print "Complete"

Outcomes