I am working on a flask app, but when I try to run this query:
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'
I get this error:
pymysql.err.ProgrammingError: (1064, “You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘WHERE Orden=WHERE Orden=’a365” at line 1”)
Thanks in advance
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I see two issues:
- extra comma for the last column update and
- two where keyword:
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'
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0