Q:

Create an Store Procedure for Insert-Update in Mysql

I'm trying to create a stored procedure to insert or update a record based on an input variable. But when I try to compile the SP simply tells me the following: Code 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'' at line 80. And I have not found the solution. Thank you very much for any help you can give me.
My SP code is as follows:
DELIMITER $$

CREATE PROCEDURE `sp_sertup`(IN i_operation CHAR(1),
                        IN i_system VARCHAR(20),
                        IN i_subsystem VARCHAR(20),
                        IN i_ref VARCHAR(20),
                        IN i_significance VARCHAR(20),
                        IN i_rank VARCHAR(20),
                        IN i_implication VARCHAR(20),
                        IN i_loc1 VARCHAR(20),
                        IN i_loc2 VARCHAR(20),
                        IN i_task VARCHAR(20),
                        IN i_time VARCHAR(20),
                        IN i_cost1 VARCHAR(20),
                        IN i_cost2 VARCHAR(20),
                        IN i_note VARCHAR(20),
                        IN i_attach VARCHAR(20),
                        IN i_operation_text VARCHAR(20),
                        IN i_id_setup INT )

BEGIN
    IF  (i_operation = 'I') THEN
        UPDATE setup_gs SET setup_status  = 0 WHERE id_setup = id_setup; 

            INSERT INTO setup_gs(
                SystemLabel,
                SubsystemLabel,
                RefLabel,
                SignificanceLabel,
                RankLabel,
                ImplicationLabel,
                Location1Label,
                Location2Label,
                TaskLabel,
                TimeLabel,
                Cost1Label,
                Cost2Label,
                NoteLabel,
                attachmentText,
                OperationsText,
                setup_status
            ) 
            VALUES 
            (
                i_system,
                i_subsystem,
                i_ref,
                i_significance,
                i_rank,
                i_implication,
                i_loc1,
                i_loc2,
                i_task,
                i_time,
                i_cost1,
                i_cost2,
                i_note,
                i_attach,
                i_operation_text,
                1);

    IF (i_operation = 'U') THEN
        UPDATE
            setup_gs
        SET
            SystemLabel        = values(i_system),
            SubsystemLabel     = values(i_subsystem),
            RefLabel           = values(i_ref),
            SignificanceLabel  = values(i_significance),
            RankLabel          = values(i_rank),
            ImplicationLabel   = values(i_implication),
            Location1Label     = values(i_loc1),
            Location2Label     = values(i_loc2),
            TaskLabel          = values(i_task),
            TimeLabel          = values(i_time),
            Cost1Label         = values(i_cost1),
            Cost2Label         = values(i_cost2),
            NoteLabel          = values(i_note),
            attachmentText     = values(i_attach),
            OperationsText     = values(i_operation_text),
            setup_status       = 1
        WHERE id_setup           = i_id_setup;          
END $$
DELIMITER ;

A:

You must finish your IF-statements with END IF in MySQL.
Also, one of your tests is between id_setup and id_setup. It should be between id_setup and i_id_setup.

