【发布时间】:2017-02-24 13:17:09
【问题描述】:
谁能告诉我为什么这不起作用
Create Procedure LeaveUpdate()
Begin
CREATE TEMPORARY TABLE leavebal AS (SELECT * FROM tbl_leave_balance WHERE month = month(DATE_SUB(now(), INTERVAL 1 MONTH)) and year = year(DATE_SUB(now(), INTERVAL 1 MONTH)));
UPDATE leavebal SET leave_balance = 0 WHERE leave_balance < 0;
UPDATE leavebal SET month = month(now()), year = year(now()), leaves_taken = 0, carry_forward = leave_balance, comp_off = 0;
UPDATE leavebal SET total_leaves = carry_forward + leaves_allowed + comp_off, leave_balance = carry_forward + leaves_allowed + comp_off;
INSERT INTO tbl_leave_balance (emp_id, month, year, carry_forward, leaves_allowed, comp_off, total_leaves, leaves_taken, leave_balance)
SELECT emp_id, month, year, carry_forward, leaves_allowed, comp_off, total_leaves, leaves_taken, leave_balance FROM leavebal;
End
【问题讨论】:
-
欢迎来到 Stack Overflow,很遗憾您的问题缺乏信息。我建议您阅读How do I ask a good question?,然后回来编辑您的问题,为我们提供所有必需的信息。否则,我们无法为您提供帮助,您的问题可能会被关闭。
标签: mysql stored-procedures temp-tables