Conditional update/insert in MySQL -
i found here topic mysql if, else query,i adapted can't figure out problem it.
here query:
if (select * `jos_import03_07_2011` `cod_oem` = 'op-4cl') null insert `jos_import03_07_2011` (`tip_imp`, `tip_produs`, `producator`, `cod_intern`, `desc`, `cod_oem`, `pret`, `valuta`) values ('imprimanta laser', 'piese schimb', 'brother', 'br-200503', '', 'op-4cl', '338.49', 'eur'); else update `jos_import03_07_2011` set `pret` = '338.49' `cod_oem` = 'op-4cl'; end if; and here error:
you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'if (select * `jos_import03_07_2011` `cod_oem` = 'op-4cl') null the' @ line 1 this original post:
conditional mysql statement. if true update, if false insert
thanks, sebastian
update
error code if exists:
you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'if exists (select * `jos_import03_07_2011` `cod_oem` = 'op-4cl') then' @ line 1
any reason can't use insert ... on duplicate key syntax?
insert `jos_import03_07_2011` (`tip_imp`, `tip_produs`, `producator`, `cod_intern`, `desc`, `cod_oem`, `pret`, `valuta`) values ('imprimanta laser', piese schimb', 'brother', 'br-200503', '', 'op-4cl', '338.49', 'eur') on duplicate key update set pret = values(pret) would far more efficient: 1 less query , far less code debug.
Comments
Post a Comment