0

In the code below, I keep getting the error An invalid SQL statement was used. [SELECT OBJECTID FROM LARA_CDC WHERE County IN ['44', '50', '74', '76']].

I've tried several different ways of formatting the query, with no luck. The end goal is to create a new file geodatabase table from selected records of an existing one. Any ideas where I'm going wrong?

new_table = "Childcare"
new_table_path = os.path.join(table_locations, new_table)
fld = "County"
query = "{0} IN ".format(arcpy.AddFieldDelimiters(table_locations, fld))
query += " ['44', '50', '74', '76']"
....
arcpy.TableToTable_conversion(table_path, table_locations, new_table, query)
  • Can you try running the query against the table in the dbms? Nothing is standing out to me as incorrect in the query, but perhaps a column name or a data type is wrong? – Zack Sep 1 '16 at 17:43
  • Fixed, see edit. – recurvata Sep 1 '16 at 18:07
  • what type of database? – Midavalo Sep 1 '16 at 18:14
  • 2
    @recurvata Your edit makes it sound like this is solved - if so I'd recommend you revert your edit back and post the solution as an answer. Self-answering is fine – Midavalo Sep 1 '16 at 18:16
  • Ok, will do that. – recurvata Sep 1 '16 at 18:24
2

Values in list are numeric, not string - removed quote marks. Also, used curved braces - () - instead of square - []. Works now.

new_table = "Childcare"
new_table_path = os.path.join(table_locations, new_table)
fld = "County"
query = "{0} IN ".format(arcpy.AddFieldDelimiters(table_locations, fld))
query += " (44, 50, 74, 76)"
....
arcpy.TableToTable_conversion(table_path, table_locations, new_table, query)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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