我试图将一些处理的结果写入SQL Server表.
我的结果存储在列表列表中,列表中的每个项目都是列表.我正在使用参数(6参数),我收到以下错误:
cnxn.execute(sqlStatement,(item [0],item [1],item [2],item [3],item [4],item [5]))
pyodbc.ProgrammingError:(‘SQL包含0个参数标记,但提供了6个参数’,’HY000′)
那是我的代码
sqlStatement = "INSERT INTO CEA_CR (`SessionID`, `Session.Call_TYPE_Assigned`, `Session.Did_Call_Type_happen_on_this_call`, `Session.Was_there_a_system_or_Rep_generated_Memo_that_matches_with_Call_Type` , 'cycle' , 'version') VALUES (%s, %s, %s, %s ,%s ,%s)"
for item in result:
wr.writerow(item)
cnxn.execute(sqlStatement, (item[0],item[1],item[2],item[3],item[4],item[5]))
cnxn.commit()
有谁知道我的执行失败的原因?
解决方法:
你应该用吗?作为参数标记,我相信.
你的SQL应该看起来像这样:
sqlStatement = "INSERT INTO CEA_CR (SessionID, Session.Call_TYPE_Assigned, Session.Did_Call_Type_happen_on_this_call, Session.Was_there_a_system_or_Rep_generated_Memo_that_matches_with_Call_Type, cycle, version) VALUES (?, ?, ?, ?, ?, ?)"
标签:pyodbc,python,sql-server,parameters
来源: https://codeday.me/bug/20190930/1834262.html