Error updating given with condition

0

I am trying to run this update but it only updates the "value" column if the "discount" column is different from 0.00. If it is 0.00 it enters the second condition of the IF and places the value of itself in value. If it is different it does the calculation_original_value - discount. Can anyone help me understand why this is occurring?

UPDATE pagamento 
SET 
valor = IF(caminho = '2',valor_original - desconto, valor)
WHERE
codigo = 5
    
asked by anonymous 17.09.2017 / 06:21

1 answer

0

By its description there is no problem with your code, but a certain confusion in the understanding. Your validation says valor must be updated with its value even if caminho equals 2; it's possible that in the case where you tested, caminho is equal to 2.
In addition, if valor is (under normal conditions) equal to valor_original - desconto , when the discount is $ 0, the value will be equal to the original value.

    
17.09.2017 / 12:24