1

I have this table:

CREATE TABLE `Factura` (
`IDFactura` BIGINT NOT NULL AUTO_INCREMENT,
`TipoDevolucionActual` VARCHAR(10) NOT NULL, 
`TipoDevolucionAnterior` VARCHAR(10) NOT NULL,
 PRIMARY KEY (`IDFactura`)
);

When trying to update a row in order to interchange TipoDevolucionActual value with TipoDevolucionAnterior value I get the same value in both fields.

I tried to do it like this:

update Factura SET 
TipoDevolucionAnterior=TipoDevolucionActual,
TipoDevolucionActual=TipoDevolucionAnterior WHERE IDFactura=1;

How can I solve this problem?

1 Answers1

1

This will work

UPDATE Factura 
    SET TipoDevolucionActual = (@temp := TipoDevolucionActual),
        TipoDevolucionActual = TipoDevolucionAnterior,
       TipoDevolucionAnterior = @temp
    WHERE IDFactura = 1;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
David Breen
  • 247
  • 1
  • 8