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