Aptivus
Aptivus

Reputation: 433

mysql update value if another one is not null

what's wrong with this query?

UPDATE `order` SET `total_no_vat` = IF(`total` IS NULL,NULL,(`total`/(1.10)));

I get an error that I cannot interpret:

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 ') )' at line 1

any clue?

Upvotes: 0

Views: 26

Answers (1)

Giorgos Betsos
Giorgos Betsos

Reputation: 72165

You can simply do:

UPDATE `order` SET `total_no_vat` = `total`/(1.10);

If total is NULL then total/(1.10) evaluates to NULL.

Upvotes: 1

Related Questions