views:

116

answers:

1

Hi,

I new to the MySQL syntax.

I have created a procedure and ran it, but it is showing some syntax probem, can you help me?

My procedure is as:

**DELIMITER $$
CREATE PROCEDURE TestAdd(
    in mODE varchar(10),
    in Id int,
    in AttName varchar(10),
    in AttValues Varchar(10)
)
IF EXISTS (SELECT * FROM AttTable WHERE id=Id) THEN
    SET Mode='Modify'
ELSE 
    SET Mode='Add'
    Start Transaction
    BEGIN
        IF (mODE='Add') THEN
            insert into atttable values (Id, AttName, AttValue);
        ELSE (if Mode='Modify') then
            update AttTable set AttName=AttName, AttValue= AttValue where Id=Id;
        END IF 
    END
$$
Delimiter ;**

Whre i am doin wrong?? Thanks in Advance.

+2  A: 

You need a BEGIN right after the parameter list at the beginning, and a matching END at the end of the procedure:

create procedure TestAdd(blah...)
BEGIN
  ...

END$$

Your first IF call is missing both THEN and END IF:

if exists ( select * from AttTable where  id=Id) THEN
  set...
ELSE
  set...
END IF

Each of the statements needs to be terminated with a ;

set Mode='Modify';
set Mode='Add';
Start Transaction;
Scott Noyes
Are you sure the statements must be terminated with a ;
Joe Philllips