If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Whats wrong with it?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-10-11, 01:57
bharanidharanit bharanidharanit is offline
Registered User
 
Join Date: Nov 2008
Posts: 115
Whats wrong with it?

Hi,
Wats wrong with this procedure? It showing errors on declare, end and end if

Code:
CREATE PROCEDURE MIS_SP_Register_Employee(
    IN _Emp_Name VARCHAR(30),
    IN _Username VARCHAR(8),
    IN _Userpwd  VARCHAR(40),
    IN _Salt VARCHAR(3),
    IN _FK_Role_ID INT,
    OUT _Emp_ID  INT)
BEGIN
    DECLARE OUT_Emp_ID INT;
    DECLARE CheckExists INT;
    SET CheckExists = 0;
  SELECT COUNT(*) INTO CheckExists FROM Employee_Master WHERE Emp_ID = _Emp_ID;
  IF (CheckExists > 0) THEN 
    INSERT INTO Employee_Master(Emp_Name,Username,Userpwd,Salt,FK_Role_ID) VALUES(_Emp_Name,_Username,_Userpwd,_Salt,_FK_Role_ID);
    SELECT OUT_Emp_ID = LAST_INSERT_ID();
  END IF;
END;
Reply With Quote
  #2 (permalink)  
Old 04-10-11, 04:43
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by bharanidharanit View Post
Wats wrong with this procedure?
you're using the semi-colon delimiter (i.e. statement terminator) inside it
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 04-10-11, 13:16
bharanidharanit bharanidharanit is offline
Registered User
 
Join Date: Nov 2008
Posts: 115
Hi thankyou,
still i am getting the error near 2nd declare
Code:
CREATE PROCEDURE MIS_SP_Register_Employee(
    IN _Emp_Name VARCHAR(30),
    IN _Username VARCHAR(8),
    IN _Userpwd  VARCHAR(40),
    IN _Salt VARCHAR(3),
    IN _FK_Role_ID int,
    OUT _Emp_ID  int)
BEGIN
    DECLARE OUT_Emp_ID INT 
    DECLARE CheckExists INT
    SET CheckExists = 0
  SELECT COUNT(*) INTO CheckExists FROM Employee_Master WHERE Emp_ID = _Emp_ID
  IF CheckExists > 0 THEN 
    INSERT INTO Employee_Master(Emp_Name,Username,Userpwd,Salt,FK_Role_ID) VALUES(_Emp_Name,_Username,_Userpwd,_Salt,_FK_Role_ID)
    SET OUT_Emp_ID = LAST_INSERT_ID()
  END IF
END
Reply With Quote
  #4 (permalink)  
Old 04-10-11, 15:00
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
you asked what was wrong, i pointed you to your poor choice of delimiter, you removed the delimiter altogether... sorry, that was the wrong answer

have you seen the mysql manual page on stored procedures?

do a search on "mysql delimiter"

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 04-19-11, 12:23
bharanidharanit bharanidharanit is offline
Registered User
 
Join Date: Nov 2008
Posts: 115
hi thankyou, i had done.
Code:
DELIMITER $$
CREATE PROCEDURE MIS_SP_Register_Employee(
    IN _Emp_Name VARCHAR(30),
    IN _Username VARCHAR(8),
    IN _Userpwd  VARCHAR(40),
    IN _Salt VARCHAR(3),
    IN _FK_Role_ID int,
    OUT _Emp_ID  int)
BEGIN
    DECLARE OUT_Emp_ID INT 
    DECLARE CheckExists INT
    SET CheckExists = 0
  SELECT COUNT(*) INTO CheckExists FROM Employee_Master WHERE Emp_ID = _Emp_ID
  IF CheckExists > 0 THEN 
    INSERT INTO Employee_Master(Emp_Name,Username,Userpwd,Salt,FK_Role_ID) VALUES(_Emp_Name,_Username,_Userpwd,_Salt,_FK_Role_ID)
    SET OUT_Emp_ID = LAST_INSERT_ID()
  END IF
END$$
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On