KevinBellSLC

Query Table FAIL!

Discussion created by KevinBellSLC on Oct 19, 2012
Latest reply on Oct 19, 2012 by curtvprice
Can anyone see any obvious blunders on my first query table?

import arcpy
arcpy.env.workspace = r'E:\gis\ims\20121017_UTA_processingMethod\Temp\qt.gdb'
try:

    tableList = ["routes","stops",'stoptimes','trips']

    fieldList = [['stoptimes.stop_id', 'stop_id'],
                  ['stoptimes.stop_code', 'stop_code'],
                  ['stoptimes.stop_name', 'stop_name'],
                  ['stoptimes.stop_desc', 'stop_desc'],
                  ['stoptimes.stop_lon', 'stop_lon'],
                  ['stoptimes.stop_lat', 'stop_lat'],
                  ['stops.route_id', 'route_id'],
                  ['stops.short_name', 'short_name'],
                  ['trips.direction_id', 'direction_id']]    

    whereClause = ''' select distinct stop_id, stop_code, stop_name, stop_desc,route_id, route_short_name, direction_id, stop_lon, stop_lat  where trip_id = trip_id and route_id = route_id and stop_id = stop_id order by route_short_name, direction_id'''
    
    lyrName = "StopsQuery"
    arcpy.MakeQueryTable_management(tableList, lyrName,"NO_KEY_FIELD", None, fieldList, whereClause)
 
    print arcpy.GetCount_management(lyrName)
 
    Fields = arcpy.ListFields(lyrName)
    for field in Fields:
        print Field.name
        
    arcpy.CopyRows_management(lyrName, r"E:\gis\ims\20121017_UTA_processingMethod\Temp\TEST.dbf")
 
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


Line 32
ERROR 999999: Error executing function.
An invalid SQL statement was used. [StopsQuery]
An invalid SQL statement was used.
An invalid SQL statement was used.
Failed to execute (MakeQueryTable).

Outcomes