0
sql_insert_query = "insert into TABLE1 (building, course, description, course_type, course_type_desc, dual_credit) 
VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE building = VALUES(building), course = VALUES(course), description = VALUES(description), course_type = VALUES(course_type), course_type_desc = VALUES(course_type_desc), dual_credit = VALUES(dual_credit);"

cursor.executemany(sql_insert_query, listCourse)

pyodbc.ProgrammingError: ('42000', u"[42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]关键字'ON'附近的语法不正确。(156) (SQLExecDirectW); [42000] [Microsoft] [SQL Server Native Client 11.0][SQL Server]无法准备语句。(8180)")

下面这个仅适用,但再次运行时会添加重复项。

"insert into TABLE1 (building, course, description, course_type, course_type_desc, dual_credit) VALUES (?, ?, ?, ?, ?, ?)"  
4

2 回答 2

0

我已经通过 tile 和 tuple 解决了它

listCourse = numpy.tile(courses, 2) listCourse = map(tuple,numpy.tile(courses, 2))

于 2020-06-09T16:19:33.893 回答
0

我绑定了 '%s' 这不起作用,所以我使用的是 '?'

于 2020-06-09T13:53:21.893 回答