Jump to content

New Procedure


ballouta

Recommended Posts

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

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.