0

我在这里所做的是,当我的 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
4

2 回答 2

0

我自己解决了实际上这个解决方案对我来说很奇怪,因为当我将参数名称从Activity_ID更改为ActivityID时,它起作用了..我不知道它发生的原因以及为什么..但它解决了我的错误

于 2013-09-05T10:52:01.927 回答
-1

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

于 2013-09-04T14:17:34.293 回答