存储过程无法正常工作

时间:2013-09-04 13:07:07

标签: mysql stored-procedures

我在这里做的是当我的record_id = 0和activity_id = 0条件失败时我正在更新我的记录。但是我得到的结果是它正在更新所有记录而不管条件 WHERE activity_id = Activity_ID (在更新tms_activity行中)

这是我在MySql中编写的程序

 CREATE PROCEDURE `EmpTimeSheet_SaveTasks`(IN user_ID INT(11),
    IN date DATE,
    IN record_ID INT(11),
    IN task_ID INT(10),
    IN Hours double,
    IN Description longtext,
    IN Updated_By_ID INT(11),
    IN Project_ID INT(11),
    IN Project_Name Varchar(50),
    IN Task_Name Varchar(50),
    IN Activity_ID INT(11),
    IN Deleted_ID Varchar(100)
    )
    BEGIN
     IF record_ID = 0 THEN

     INSERT IGNORE INTO tms_timesheet(user_id, date, is_freezed)  VALUES (user_ID,date,0);
     SET @ID = (SELECT record_id FROM tms_timesheet WHERE user_id= user_ID  and date=date);
     INSERT INTO tms_activity (timesheet_id, task_id, hours, description, updated_on, updated_by_id,project_id,project_name,task_name )  VALUES (@ID ,task_ID,Hours ,Description, CURRENT_TIMESTAMP( ) ,user_ID,Project_ID,Project_Name ,Task_Name );

     ELSE IF Activity_ID = 0 THEN

    INSERT INTO tms_activity ( timesheet_id, task_id, hours, description, updated_on, updated_by_id,project_id,project_name,task_name )  VALUES (record_ID ,task_ID,Hours ,Description, CURRENT_TIMESTAMP( ) ,user_ID, Project_ID ,Project_Name,Task_Name);

    ELSE

         UPDATE tms_activity  SET  task_id=task_ID, hours=Hours, description=Description, updated_on=CURRENT_TIMESTAMP( ),    updated_by_id=user_ID,project_id=Project_ID,task_name=Task_Name,project_name=Project_Name *****WHERE activity_id = Activity_ID;*****
     END IF;

     END IF;

    IF Deleted_ID!='' THEN

     DELETE FROM tms_activity where activity_id in (Deleted_ID);

    END IF;

    END

2 个答案:

答案 0 :(得分:0)

我自己解决了它实际上解决方案对我来说很安静,因为当我将参数名称从 Activity_ID 更改为 ActivityID 时,它工作了......我不知道原因它是如何发生的和WHY ..但它解决了我的错误

答案 1 :(得分:-1)

问题可能是var名称。 尝试将“Activity_ID”更改为“vActivity_ID”。