我正在嘗試將一些處理的結果寫入SQL Server表中。 我的結果存儲在列表中,列表中的每個項目都是列表。我正在使用參數(6 params),並且出現以下錯誤:Python中參數查詢的語法(pyodbc)
cnxn.execute(sqlStatement,(item [0],item [1],item [2],item [3],item [4 ]項[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驅動程序,但不應參數替換爲'',而不是'%s'? https://code.google.com/p/pyodbc/wiki/GettingStarted – RickyA 2014-11-06 13:37:13