python code #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 Add the following to your script after you create your query layer. t = arcpy.mapping.TableView(test[0]) arcpy.TableToTable_conversion(t, workspace, "hz002") If you want it to save as a dbf, you can replace the TableToTable with: arcpy.TableToDBASE_conversion(t, r"Z:/Projects/HazardTrees") See TableView for more details.
... View more