【发布时间】:2022-08-15 13:56:37
【问题描述】:
cursor.execute(\"\"\" if exists ( SELECT * from Alert where alert = ? and date = ? and devicename = ? )
BEGIN
update Alert set alert = ? where alert = ? and date = ? and devicename = ?
END
ELSE
BEGIN
INSERT INTO Alert (alert,date,devicename) VALUES (?, ?, ?) \"\"\", row[1], row[0], filename[:-4],
row[1], row[1], row[0], filename[:-4], row[1], row[0], filename[:-4])
cursor.commit()
上面的代码是我对 SQLServer 的 sql 查询。如果我更换它,它会起作用吗?有价值,但如果我这样做,我会收到错误。需要帮忙。我正在使用 pyodbc 库顺便说一句。
cursor.execute(\"\"\" if exists (SELECT * from Alert where alert = ? and date = ? and devicename = ?) pyodbc.ProgrammingError: (\'42000\', \"[42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]\')\' 附近的语法不正确。(102) (SQLExecDirectW); [42000] [ Microsoft][SQL Server Native Client 11.0][SQL Server]无法准备语句。(8180)\")
标签: python sql-server