import arcpy from arcpy import env env.workspace ="C:/RG/Projects/CriticalDataNetwork/CDEC.gdb" try: inTable = "Avg_Daily" keyField = "STATION_ID" inField = [["Avg_Daily.OBJECTID","OBJECTID",],["Avg_Daily.STATION_ID","STATION_ID"], ["Avg_Daily.DLY_AVG", "DLY_AVG"]] whereClause = "\"STATION_ID\" = 'CAP', 'DDM'" outTable = "Test" arcpy.MakeQueryTable_management(inTable, outTable, "USE_KEY_FIELDS", keyField, inField, whereClause) except Exception, e: # If an error occurred, print line number and error message import traceback, sys tb = sys.exc_info()[2] print "Line %i" % tb.tb_lineno print e.message
Solved! Go to Solution.
Now, the code runs without any problem, however, I can't see the output file. Any clue?
arcpy.TableToGeodatabase_conversion(outTable, "C:/RG/Projects/CriticalDataNetwork/CDEC.gdb")
whereClause = "\"STATION_ID\" = 'CAP', 'DDM'"
So you want to select if station id is CAP or DDM?
I'm not sure you can comma separate those it might need to be
whereClause = "\"STATION_ID\" = 'CAP' OR "\"STATION_ID\"= 'DDM'"
See if that works
Or try:
whereClause = "\"STATION_ID\" IN ('CAP', 'DDM')"
Now, the code runs without any problem, however, I can't see the output file. Any clue?
arcpy.TableToGeodatabase_conversion(outTable, "C:/RG/Projects/CriticalDataNetwork/CDEC.gdb")
arcpy.Select_analysis(myInputTblPath, myOutputTblPath, "STATION_ID in ('CAP','DDM')") #or arcpy.MakeTableView_management(myInputTblPath, "my_table_view", "STATION_ID in ('CAP','DDM')")
Really, the MakeQueryTable tool is geared around doing complex queries with multiple related tables.
If you just want to extract some records to a new on-disk table use the Select_analysis tool.
If you want to make a in-memory pointer to some particular records in a table (aka 'a view') use the MakeTableView tool.
For example:arcpy.Select_analysis(myInputTblPath, myOutputTblPath, "STATION_ID in ('CAP','DDM')") #or arcpy.MakeTableView_management(myInputTblPath, "my_table_view", "STATION_ID in ('CAP','DDM')")
BTW: Per my undersatnding, a QueryTable and TableView (and a FeatureLayer as well) do not store the actual records of the table in memory (aka the RAM). Rather they store references to the on-disk records. Basically it builds a hash table of the key fields that satisfy a particular SQL query. Only the keys and their relationships are stored in RAM.
import arcpy from arcpy import env try: inTable = ["Database Connections/OLE DB Connection.odc/ORADBA.COUNTY"] inField = [["ORADBA.COUNTY.OBJECTID", 'OBJECTID'], ["ORADBA.COUNTY.COUNTY_NUM", 'COUNTY_NUM'],\ ["ORADBA.COUNTY.COUNTY_NAME", 'COUNTY_NAME']] keyField = "ORADBA.COUNTY.OBJECTID" whereClause = "\"ORADBA.COUNTY.COUNTY_NAME\" = 'ORADBA.COUNTY.KINGS'" outTable = "C:/RG/Projects/CriticalDataNetwork/CDEC/Kings" arcpy.MakeQueryTable_management(inTable, outTable, "USE_KEY_FIELDS", keyField, inField, whereClause) arcpy.TableToGeodatabase_conversion(outTable, "C:/RG/Projects/CriticalDataNetwork/CDEC.gdb") except Exception, e: # If an error occurred, print line number and error message import traceback, sys tb = sys.exc_info()[2] print "Line %i" % tb.tb_lineno print e.message