ballouta Posted April 6, 2011 Share Posted April 6, 2011 Hello I have a customers table: +-------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+----------------+ | customer_id | int(11) | NO | PRI | NULL | auto_increment | | last_name | varchar(50) | NO | | NULL | | | first_name | varchar(50) | NO | | NULL | | | dob | date | YES | | NULL | | | phone | varchar(20) | YES | | NULL | | +-------------+-------------+------+-----+---------+----------------+ i want to write a stored procedure that accepts as parameters all customers table columns. if customer id is 0 or NULL, then make insertion, otherwise an update. This is the code i wrote: delimiter // create procedure customer_proc (IN cus_id INT(11), IN lname VARCHAR(50), IN fname VARCHAR(50), IN dobirth date, IN phone_num VARCHAR(20)) BEGIN IF cus_id == 0 OR cus_id IS NULL THEN insert into customers (last_name, first_name, dob, phone) values (lname, fname, dobirth, phone_num); ELSE update customers set last_name = lname, first_name = fname, dob = dobirth, phone = phone_num where customer_id = cus_id; END IF; END; // I got this error: ERROR 1064 (42000): 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 '== 0 OR cus_id IS NULL THEN insert into customers (last_name, first_name, dob,' at line 3 Thank you very much Link to comment https://forums.phpfreaks.com/topic/232833-new-procedure/ Share on other sites More sharing options...
fenway Posted April 19, 2011 Share Posted April 19, 2011 There is no ==. Link to comment https://forums.phpfreaks.com/topic/232833-new-procedure/#findComment-1203423 Share on other sites More sharing options...
ballouta Posted April 19, 2011 Author Share Posted April 19, 2011 Thank you Link to comment https://forums.phpfreaks.com/topic/232833-new-procedure/#findComment-1203549 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.