#Import system modules import arcpy arcpy.env.overwriteOutput = True # Set data path also tried removing the r and change / to // workspace = r"Z:/Projects/HazardTrees/Results.gdb" intable = r"Z:/Projects/HazardTrees/Results.gdb/Veg_HazardTreeSurvey_tbl" inpsekigistest_HazardTrees_sde = r"Z:/Projects/HazardTrees/inpsekigistest_HazardTrees.sde" arcpy.env.workspace = workspace arcpy.env.scratch = workspace # Create the Query Layer and return the Table-View name for verification test = arcpy.MakeQueryLayer_management(inpsekigistest_HazardTrees_sde, "HazTree", "SELECT * from SEKI_HazardTrees.dbo.Veg_HazardTreeSurvey_tbl_VW", "OBJECTID", "", "", "").getOutput(0) # Get the properties of the Query Layer if possible objMQ = arcpy.Describe(test) print objMQ.name print objMQ.dataType print objMQ.nameString print objMQ.path print test # Get column count - note that if the MakequeryLayer function fails, then an empty table with only the schema will be produced. # However, we have tested this and copied the SQL query and parameters from ArcMap tools for which we were successful generating the Table View so this should be ok #print int(arcpy.GetCount_management(test).getOutput(0)) # doesn't work #print int(arcpy.GetCount_management("HazTree").getOutput(0)) # doesn't work #arcpy.CopyRows_management(test, r"Z:/Projects/HazardTrees/hz002.dbf") # doesn't work Error 99999 #arcpy.CopyRows_management(test, "Z://Projects//HazardTrees//hz002.dbf") # doesn't work Error 99999
#Import system modules import arcpy arcpy.env.overwriteOutput = True # Set data path also tried removing the r and change / to // workspace = r"Z:/Projects/HazardTrees/Results.gdb" intable = r"Z:/Projects/HazardTrees/Results.gdb/Veg_HazardTreeSurvey_tbl" inpsekigistest_HazardTrees_sde = r"Z:/Projects/HazardTrees/inpsekigistest_HazardTrees.sde" arcpy.env.workspace = workspace arcpy.env.scratch = workspace # Create the Query Layer and return the Table-View name for verification test = arcpy.MakeQueryLayer_management(inpsekigistest_HazardTrees_sde, "HazTree", "SELECT * from SEKI_HazardTrees.dbo.Veg_HazardTreeSurvey_tbl_VW", "OBJECTID", "", "", "").getOutput(0) # Get the properties of the Query Layer if possible objMQ = arcpy.Describe(test) print objMQ.name print objMQ.dataType print objMQ.nameString print objMQ.path print test t = arcpy.mapping.TableView(test[0]) arcpy.TableToTable_conversion(t, workspace, "hz002") # Get column count - note that if the MakequeryLayer function fails, then an empty table with only the schema will be produced. # However, we have tested this and copied the SQL query and parameters from ArcMap tools for which we were successful generating the Table View so this should be ok #print int(arcpy.GetCount_management(test).getOutput(0)) # doesn't work #print int(arcpy.GetCount_management("HazTree").getOutput(0)) # doesn't work #arcpy.CopyRows_management(test, r"Z:/Projects/HazardTrees/hz002.dbf") # doesn't work Error 99999 #arcpy.CopyRows_management(test, "Z://Projects//HazardTrees//hz002.dbf") # doesn't work Error 99999
Had the same issue. This works, thank you Leonard Rugiel so much! I couldn't do anything with the table view coming from the Make Query Layer tool until now.
Will this code also work if you need to create a featurelayer from the query layer instead of a tableview?
Not sure whether this addresses your problem but I found it (and then this thread) during my search for solving another issue. Based on it, you may want to check that background geoprocessing is turned off.
Can't get reference to result from MakeQueryLayer_management