【问题标题】:how to solve syntax error on sql on my flask app?如何解决我的烧瓶应用程序上的 sql 语法错误?
【发布时间】:2021-11-26 17:56:12
【问题描述】:

我正在开发一个烧瓶应用程序,但是当我尝试运行此查询时:

UPDATE Servi 
SET Orden = CASE WHEN Orden IS NOT NULL THEN '%s' END,
    Dependencia = CASE WHEN Dependencia IS NOT NULL THEN '%s' END, 
    Atencion = CASE WHEN Atencion IS NOT NULL THEN '%s' END,  
    Recibio_del_cer = CASE WHEN Recibio_del_cer IS NOT NULL THEN '%s' END,   
    Entrego_al_cer = CASE WHEN Entrego_al_cer IS NOT NULL THEN '%s' END,   
    Folio = CASE WHEN Entrego_al_cer IS NOT NULL THEN '%s' END,    
    Entrada = CASE WHEN Entrego_al_cer IS NOT NULL THEN '%s' END,     
    Equipo = CASE WHEN Equipo IS NOT NULL THEN '%s' END,    
    Marca = CASE WHEN Marca IS NOT NULL THEN '%s' END,    
    Modelo = CASE WHEN Modelo IS NOT NULL THEN '%s' END,    
    Serie = CASE WHEN Serie IS NOT NULL THEN '%s' END,    
    Unidad = CASE WHEN Unidad IS NOT NULL THEN '%s' END,    
    Delegacion = CASE WHEN Delegacion IS NOT NULL THEN '%s' END,    
    Accesorio = CASE WHEN Accesorio IS NOT NULL THEN '%s' END,    
    Falla = CASE WHEN Falla IS NOT NULL THEN '%s' END,   
    Ticket = CASE WHEN Ticket IS NOT NULL THEN '%s' END,    
    Status = CASE WHEN Status IS NOT NULL THEN '%s' END,   
    Reparacion = CASE WHEN Reparacion IS NOT NULL THEN '%s' END,   
    Salida = CASE WHEN Salida IS NOT NULL THEN '%s' END,   
    Reparo = CASE WHEN Reparo IS NOT NULL THEN '%s' END,   
    Servicio = CASE WHEN Servicio IS NOT NULL THEN '%s' END,    
    Reporte = CASE WHEN Reporte IS NOT NULL THEN '%s' END,   
WHERE Orden=WHERE Orden='%s'

我收到此错误:

pymysql.err.ProgrammingError: (1064, "您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,以了解在 'WHERE Orden=WHERE Orden='a365'' 附近使用的正确语法在第 1 行")

提前致谢

【问题讨论】:

  • 错误是由于这行Reporte=case when Reporte is not null then '% s' end,删除,太多了

标签: python mysql sql


【解决方案1】:

我看到两个问题:

  1. 最后一列更新的额外逗号和
  2. 两个where关键字:
UPDATE Servi 
SET 
   Orden= case when Orden is not null then '%s' end,
   Dependencia=case when Dependencia is not null then '%s' end, 
   Atencion=case when Atencion is not null then '%s' end,  
   Recibio_del_cer=case when Recibio_del_cer is not null then '%s' end,   
   Entrego_al_cer=case when Entrego_al_cer is not null then '%s' end,   
   Folio=case when Entrego_al_cer is not null then '%s' end,    
   Entrada=case when Entrego_al_cer is not null then '%s' end,     
   Equipo=case when Equipo is not null then '%s' end,    
   Marca=case when Marca is not null then '%s' end,    
   Modelo=case when Modelo is not null then '%s' end,    
   Serie=case when Serie is not null then '%s' end,    
   Unidad=case when Unidad is not null then '%s' end,    
   Delegacion=case when Delegacion is not null then '%s' end,    
   Accesorio=case when Accesorio is not null then '%s' end,    
   Falla=case when Falla is not null then '%s' end,   
   Ticket=case when Ticket is not null then '%s' end,    
   Status=case when Status is not null then '%s' end,   
   Reparacion=case when Reparacion is not null then '%s' end,   
   Salida=case when Salida is not null then '%s' end,   
   Reparo=case when Reparo is not null then '%s' end,   
   Servicio=case when Servicio is not null then '%s' end,    
   Reporte=case when Reporte is not null then '%s' end   
WHERE Orden='%s'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 2017-01-12
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    • 1970-01-01
    相关资源
    最近更新 更多