【发布时间】:2017-11-07 13:20:04
【问题描述】:
我正在尝试将多个参数传递给 sql 查询,但它给我带来了错误,
这里是查询
cbd_id=[1,10,19,31,37,42,48,57,63,64,65]
cursor.execute('''select t1.id as pid,pxval,pyval from <tbl1> t1 left join (select * from <tbl2> where clubid=? t2 on t1.id=t2.projectid where t1.cityid in (SELECT cityid FROM <tbl3> WHERE cbdid =? group by cityid) and t1.pxval>0 and t2.distance is null order by projectid)''',(cbd_id[i],cbd_id[i]))
它给了我错误
ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 't2'. (102) (SQLExecDirectW)")
但是我查了没发现问题,
对此的任何建议都会有所帮助。
谢谢
【问题讨论】:
-
您可能在某处遗漏了右括号。一个示例是在
t2别名之前缺少的那个。应该是select t1.id as pid,pxval,pyval from <tbl1> t1 left join (select * from <tbl2> where clubid=?) t2。
标签: python sql sql-server pyodbc