salix/db/routines/vn/procedures/workerTimeControlSetOrder.sql

17 lines
411 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`workerTimeControlSetOrder`()
BEGIN
SET @order := 1;
SET @userFk := 0;
SET @day := 0;
UPDATE tmp.workerTimeControl
SET `order` = IF(userFk = @userFk AND day(timed) = @day, @order := @order + 1, @order := 1),
userFk = @userFk := userFk,
manual = manual + (0 * @day := day(timed))
ORDER BY userFk, timed;
END$$
DELIMITER ;