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

25 lines
807 B
MySQL
Raw Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`workerDepartmentByDate`(vDate DATE)
BEGIN
DROP TEMPORARY TABLE IF EXISTS tmp.workerDepartmentByDate;
CREATE TEMPORARY TABLE tmp.workerDepartmentByDate
ENGINE = MEMORY
SELECT w.id userFk,
w.lastName name,
w.firstName firstname,
d.name department,
d.id departmentFk,
b.started,
d.isProduction,
CAST(12 * b.amount / ct.hoursWeek / 52 AS DECIMAL(10,2)) costeHora,
w.fi nif
FROM business b
JOIN calendarType ct ON ct.id = b.calendarTypeFk
JOIN department d ON d.id = b.departmentFk
JOIN worker w ON w.id = b.workerFk
WHERE b.started <= vDate
AND (b.ended > vDate OR b.ended IS NULL);
END$$
DELIMITER ;