>>> arcpy.MakeQueryLayer_management('Database Connections\my_database.sde','a_table_view','select a_field from some_table','a_field')
>>> mxd = arcpy.mapping.MapDocument("CURRENT") >>> df = mxd.activeDataFrame >>> arcpy.mapping.ListLayers(mxd,data_frame=df) [] >>> arcpy.mapping.ListTableViews(mxd,data_frame=df) [] >>>
arcpy.mapping.TableView('a_table_view')
Solved! Go to Solution.
I was having the same problem with not being able to get the resulting table from MakeQueryLayer when not using a spatial column. I'm trying to work with this in a standalone python script so I'm not trying to add a table to ArcMap. I just want to copy out the table as a standalone table in some file geodatabase i'm working with.
I stumbled upon another forum (Table analog of MakeQueryLayer) that made me realize
I still think there's a bug as the help for MakeQueryLayer in 10.2.2 says "If the SQL query does not return a spatial column, the output will be a stand-alone table." which isn't true as it appears to return a pointer to a database (maybe similar to a sql view?). I'll contact ESRI about this.
Here's how i got it working in my python code:
arcpy.MakeQueryLayer_management(database_connection,"out_layer_name", query,"FIELD1;FIELD2")
desc = arcpy.Describe("out_layer_name")
t = arcpy.mapping.TableView(desc.name)
arcpy.CopyRows_management(t, "myoutputtable")
This is a know bug and the bug # is NIM086004.
The workaround i listed where you could "describe" the layer and turn ultimately into a table seems like the best workaround in the meantime.
It's great that a work around has been found for Python but Esri should really look at fixing this, especially as it's still an issue in 10.3.1. In Model Builder (thankfully we're not using it!) there's no way to use arcpy.Describe or mapping.TableView unless you add a python script to the model. There's another thread about this problem Create Query Layer Tool Output Object Not Found or Recognized which came to much the same conclusion.
Folks is this bug back in 10.4.1 ? I appear to be getting it again .. Maybe ESRI never fixed it
I just checked the status of the bug # previously referenced and the status is "In Product Plan", so i guess that means it hasn't been addressed yet. :<(
Still present in 10.6, though it's fixed in ArcPro. I've summarized your and Tim Haverland diagnosis and solution at arcmap - Make Query Layer - where are the results? - Geographic Information Systems Stack Exchange . Thank you for getting me on the right track!