Всем привет!
Написал триггер, но не работает!!!
Посмотрите пож-а:
DROP TRIGGER IF EXISTS `UpdateBuildingAnalysis2` $$
CREATE DEFINER=`root`@`%` TRIGGER `UpdateBuildingAnalysis2` before UPDATE ON `MObjectBuildings` FOR EACH ROW
BEGIN
DECLARE analysis varchar(100);
SET analysis =
CASE
WHEN old.Fabric IS NULL OR old.Fabric = '' THEN 'notactual'
WHEN old.Fabric LIKE '%Саманное%' OR old.Fabric LIKE '%каркасно-камышитовое%' THEN 'demolition'
ELSE (
CASE
WHEN old.Status LIKE '%неработающее%' OR old.Status LIKE '%в резерве%' OR old.Status LIKE '%находится в ремонте%' THEN 'demolition'
WHEN old.Fabric LIKE '%кирпичное%' AND (YEAR(CURDATE()) - YEAR(old.Year)) > 50 THEN 'demolition'
WHEN old.Fabric LIKE '%деревянное%' AND (YEAR(CURDATE()) - YEAR(old.Year)) > 20 THEN 'demolition'
WHEN old.Fabric LIKE '%панельное%' AND (YEAR(CURDATE()) - YEAR(old.Year)) > 40 THEN 'demolition'
WHEN old.Fabric LIKE '%каркасное с кирпичным заполнением%' AND (YEAR(CURDATE()) - YEAR(old.Year)) > 16 THEN 'demolition'
WHEN old.Fabric LIKE '%каркасное навесными панелями%' AND (YEAR(CURDATE()) - YEAR(old.Year)) > 12 THEN 'demolition'
WHEN old.Status LIKE '%работающее%' OR old.Status LIKE '%прочее%' OR new.Status LIKE '%требует ремонта%' OR old.Status LIKE '%не указан%' THEN
(
CASE
WHEN old.Fabric LIKE '%кирпичное%' AND (YEAR(CURDATE()) - YEAR(old.Year)) >= 25 AND (YEAR(CURDATE()) - YEAR(old.Year)) <= 50 THEN 'repair'
WHEN old.Fabric LIKE '%деревянное%' AND (YEAR(CURDATE()) - YEAR(old.Year)) >= 8 AND (YEAR(CURDATE()) - YEAR(old.Year)) <= 20 THEN 'repair'
WHEN old.Fabric LIKE '%панельное%' AND (YEAR(CURDATE()) - YEAR(old.Year)) >= 16 AND (YEAR(CURDATE()) - YEAR(old.Year)) <= 40 THEN 'repair'
WHEN old.Fabric LIKE '%каркасное с кирпичным заполнением%' AND (YEAR(CURDATE()) - YEAR(old.Year)) >= 7 AND (YEAR(CURDATE()) - YEAR(old.Year)) <= 16 THEN 'repair'
WHEN new.Fabric LIKE '%каркасное навесными панелями%' AND (YEAR(CURDATE()) - YEAR(old.Year)) >= 5 AND (YEAR(CURDATE()) - YEAR(old.Year)) <= 12 THEN 'repair'
ELSE 'normal'
END
)
ELSE 'normal'
END
)
END;
IF(analysis != old.`Analysis`) THEN
SET old.`Analysis` = analysis;
END IF;
END
Выходит ошибка:Updating of OLD row is not allowed in trigger
Что сделать?