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
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.