Click here to Skip to main content
15,878,970 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
create procedure rht_users_insert
(
    IN  p_user_id int,
    IN  p_client_id int,
    IN  p_first_name varchar(50),
    IN  p_last_name varchar(50),
    IN  p_login_id varchar(60),
    IN  p_password varchar(200),
    IN  p_status varchar(10)
);

BEGIN

if not exists(select client_id from rht_users where user_id=p_user_id)then
BEGIN
select p_user_id=ifnull(max(user_id),0)+1 from rht_users


insert into rht_users
(user_id,client_id,first_name,last_name,login_id, password,status)
values(p_user_id,p_client_id,p_first_name,p_last_name,p_login_id,
       p_password,p_status)
END
else
update rht_users set user_id=@user_id,client_id=@client_id,first_name=@first_name,
last_name=@last_name,login_id=@login_id,password=@password,status=@status)
where user_id=@user_id

END
Posted
Updated 22-Mar-15 21:01pm
v2
Comments
Kornfeld Eliyahu Peter 23-Mar-15 5:14am    
What error?
samip rot 23-Mar-15 5:28am    
#1064 - 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 ';

BEGIN

if not exists(select client_id from rht_users where user_id=p_us' at line 10

1 solution

You have syntax error... ; is a command separator in MySQL (and other SQLs too)...
When you put an ; at the end of the line you actually separates two independent commands...
SQL
create procedure rht_users_insert
(
    IN  p_user_id int,
    IN  p_client_id int,
    IN  p_first_name varchar(50),
    IN  p_last_name varchar(50),
    IN  p_login_id varchar(60),
    IN  p_password varchar(200),
    IN  p_status varchar(10)
); /* this ; separates the header and the body of your stored procedure and creates a syntax error */

BEGIN
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900