我已经创建了一个工作正常的程序,但它永远不会进入if块。在if中,我将leave_Type与'Cl'进行比较。
CREATE DEFINER=`satish`@`%` PROCEDURE `p_Leave_Approval`(
IN uname varchar(45),
IN coment varchar(200),
IN approval varchar(1)
)
BEGIN
-- declare str varchar(2);
-- set str = 'CL';
SELECT Emp_ID INTO @empid
FROM employee
WHERE Emp_F_Name=uname;
UPDATE staff_leave_detail
SET Leave_Comment=coment
,Leave_Status=approval
WHERE Emp_ID=@empid
AND Leave_Status='P';
SELECT Leave_Start_Date, Leave_End_Date INTO @sd, @ed
FROM staff_leave_detail
WHERE Emp_ID=@empid AND Leave_Status='P';
SELECT DATEDIFF(@sd,@ed) AS 'd2 - d1' INTO @s;
SELECT Leave_Type INTO @lt
FROM staff_leave_detail
WHERE Emp_ID=@empid
AND Leave_Status='P';
IF @lt = 'CL' THEN
UPDATE staff_leave
SET AP_CL = AP_CL - @s ,
AV_CL = AV_CL + @S
WHERE Emp_ID = @empid ;
END IF;
END
答案 0 :(得分:1)
如果您打算比较
中的字符串IF @lt = 'CL' THEN
那么你不应该使用字符串比较功能吗?
http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html