BEGIN
DECLARE month_num INT;
SET month_num = 1; -- Start with January
WHILE month_num <= 12 DO
DECLARE month_str CHAR(2);
SET month_str = LPAD(month_num, 2, '0'); -- Format month as 01, 02, ...
DECLARE count_rows INT;
SET count_rows = (SELECT COUNT(1) FROM attendance_workday WHERE date_ymd LIKE CONCAT('2024', month_str, '%'));
IF count_rows > 0 THEN
-- Perform UPDATE statements for the current month
-- Replace placeholders with actual UPDATE statements for each month
EXECUTE IMMEDIATE CONCAT('UPDATE attendance_workday SET date_ymd = '2024', month_str, '01', ', is_work = '1' WHERE date_ymd LIKE '2024', month_str, '%'');
-- Add similar UPDATE statements for other dates in the month
ELSE
-- Perform INSERT statements for the current month
-- Replace placeholders with actual INSERT statements for each month
EXECUTE IMMEDIATE CONCAT('INSERT INTO attendance_workday (date_ymd, is_work) VALUES (''2024', month_str, '01'', ''1''), (''2024', month_str, '02'', ''1''), ...');
-- Add remaining date-is_work pairs for the month
END IF;
SET month_num = month_num + 1; -- Move to the next month
END WHILE;
END