Error updating given with condition

Asked

Viewed 40 times

0

I’m 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 he enters the second condition of the IF and puts in value the value of himself. If different, it makes the original value calculation - discount. Can anyone help me understand why this is happening?

UPDATE pagamento 
SET 
valor = IF(caminho = '2',valor_original - desconto, valor)
WHERE
codigo = 5
  • X - 0 = X ... what’s the problem ?

1 answer

0


By your description there is no problem with your code, but rather a certain confusion in the understanding.
Its validation says valor should be updated with the value of the same case caminho is equal to 2; it is possible that in the case you tested, the caminho is yes equal to 2.
In addition, case valor is (under normal conditions) equal to valor_original - desconto, when the discount is R$0, the value will be equal to the original value.

  • You are absolutely right. That is the result of doing things with a hot head...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.