mysql - UPDATE if exists else INSERT in SQL -


i'm trying implement sql query "update if exists else insert"

my table(allowance) below:

employeeid int(8) pk year year(4) pk month int(2) pk overtime decimal(10,2) medical decimal(10,2) lunch decimal(10,2) bonus decimal(10,2) allowance decimal(10,2) 

below sql query tried:

if exists (select * allowance employeeid =10000001 , year = 2014 , month = 4)     update allowance     set overtime = 10.00, medical = 10.00, lunch = 10.45, bonus =10.10, allowance = 40.55     employeeid =10000001 , year = 2014 , month = 4 else     insert allowance values (10000001,2014,4,10.00,10.00,10.45,10.10,40.55) 

i keep getting error message:

"#1064 - have error in sql syntax; check manual corresponds mysql server version right syntax use near 'if exists (select * allowance employeeid =10000001 , year = 2014 an' @ line 1 "

can please help??

the below query fulfill requirement.

insert `allowance` (`employeeid`, `year`, `month`, `overtime`,`medical`, `lunch`, `bonus`, `allowance`) values (10000001, 2014, 4, 10.00, 10.00, 10.45, 10.10, 40.55) on duplicate key update `employeeid` = 10000001 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -