Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

When I run this code, it says "An invalid SQL statement was used". Any idea what does it mean?

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"
    print outTable

    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
share|improve this question

1 Answer 1

up vote 3 down vote accepted

you cannot use equal with more than one value

use either in or OR to do this

"\"STATION_ID\" IN ('CAP', 'DDM')"

"\"STATION_ID\" = 'CAP' OR \"STATION_ID\" = 'DDM'"

note that I recommand using """ to clarify your strings

""" "STATION_ID" IN ('CAP', 'DDM') """

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.