AnsweredAssumed Answered

How to Join a Feature Layer to a Query Layer?

Question asked by BrokenLegMike on Apr 20, 2016
Latest reply on Apr 20, 2016 by Dan_Patterson

I am trying to join a SDE feature class to a Query Layer via Python. I don't seem to have any issues doing this manually in ArcMap, but everytime I get to the join portion of my script, it fails with ERROR: 000229. I've turned off Background Geoprocessing. That doesn't seem to help. I've tried a few ways of accessing the query table in the join function, but it always returns the same error message (tried using "Describe" to grab the name of the query table, tried to use the "ake Table View" function on the query layer, none of which seems to work)


import arcpy
from arcpy import env

env.workspace = r"Database Connections\PRD.sde"

# Local variables:
PRD_sde = "Database Connections\\PRD.sde"
query = "My query" # This is a bonified and varified query. It's just a little large for this post

# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management("SPATIAL.TENURE_SVW", "selected_tenures", "TENURE_NUMBER_ID in (216720,216721,216722,216723,216724,216725)", "")

# Process: Make Query Layer
arcpy.MakeQueryLayer_management(PRD_sde, "Table_Test", query, "TENURE_NUMBER_ID", "", "", "")

# Process: Add Join
arcpy.AddJoin_management("selected_tenures", "TENURE_NUMBER_ID", "Table_Test", "TENURE_NUMBER_ID", "KEEP_ALL")