【问题标题】:python update Query with subtracting columnspython更新查询与减去列
【发布时间】:2019-03-17 10:24:56
【问题描述】:

我试图在 python 中运行 sql 查询来更新数量,但我得到了错误。

cur.execute(
  "UPDATE Products SET Price =? , Quantity =? , RackLocation =? WHERE ID =?",
   [self.new_price.get(), self.new_quantity.get(), self.new_racklocation.get(), self.id]
)

我收到此错误:

[int(self.new_quantity.get()) ,  int(self.id)])    
pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL Server Driver]
[SQL Server]Incorrect syntax near '='. (102) (SQLExecDirectW); [42000] 
[Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be 
prepared. (8180)")

【问题讨论】:

  • 如果您只是将它们打印到控制台,您的 get 方法会返回什么?
  • Edit你的问题并解释“减列”的含义
  • 您好,谢谢您的回复,其实我的查询是错误的。我将我的查询更改为它有效。
  • cur.execute("UPDATE Products SET Quantity = Quantity - 1 WHERE ID=?", [self.id])

标签: python pyodbc


【解决方案1】:

我做错了。查询应该是这样的

cur.execute("UPDATE Products SET Quantity = Quantity - 1 WHERE ID=?", [self.id])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-05
    • 1970-01-01
    • 2022-02-03
    • 2019-05-14
    • 2015-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多