Всем привет! Выходит это ошибка при вставке в таблицу данные.
Этот же код нормально работает для триггера Before Update, а для Before Insert выдает ошибку, типа много чем одной строки как я понял.
Вот мой код:
DROP TRIGGER IF EXISTS `InsertBuildingAnalysis`;
CREATE TRIGGER `InsertBuildingAnalysis` BEFORE INSERT ON `MDepartments` FOR EACH ROW BEGIN
DECLARE population INT;
DECLARE normative, isnornamtive INT;
DECLARE locality VARCHAR(1256);
DECLARE loc_dis_id int;
DECLARE loc_isCenter int;
DECLARE sub_pop int;
DECLARE sub_cpop int;
DECLARE dis_pop int;
SET population = (SELECT new_fnc(new.ParentId));
SET locality = (SELECT * FROM Localities WHERE Localities.Id = new.LocalityId);
SET loc_dis_id = (SELECT Localities.DistrictId FROM Localities WHERE Localities.Id = new.LocalityId);
SET loc_isCenter = (SELECT Localities.IsCenter from Localities WHERE Localities.Id = new.LocalityId);
SET sub_pop = (SELECT new_fnc2(new.SubRegionId));
SET sub_cpop = (SELECT new_fnc3(new.SubRegionId));
SET dis_pop = (SELECT new_fnc4(loc_dis_id));
IF (new.TypeId = 4 ) THEN
IF (population < 50) THEN
SET new.Normative = 0;
SET new.IsNormativePositive = 1;
ELSEIF (population > 8000) THEN
SET new.Normative = 0;
SET new.IsNormativePositive = 0;
ELSE
SET new.Normative = 1;
END IF;
ELSEIF (new.TypeId = 3) THEN
IF (population < 800) THEN
SET new.Normative = 1;
SET new.IsNormativePositive = 1;
ELSEIF (population > 2000) THEN
SET new.Normative = 0;
SET new.IsNormativePositive = 0;
ELSE
SET new.Normative = 1;
END IF ;
ELSEIF (new.TypeId = 2) THEN
IF (population > 800 && population <= 2000) THEN
SET new.Normative = 2;
ELSEIF (population > 2000 ) THEN
SET new.Normative = 1;
ELSE
SET new.Normative = 0;
SET new.IsNormativePositive = 1;
END IF;
ELSEIF (new.TypeId = 57) THEN
IF(population < 10000) THEN
SET new.Normative = 0;
SET new.IsNormativePositive = 1;
ELSE
SET new.Normative = 1;
END IF;
ELSEIF (new.TypeId = 26)THEN
IF (!locality) THEN
SET new.Normative = -1;
ELSEIF (loc_isCenter != 1) THEN
SET new.Normative = -2;
ELSE
SET new.Normative = 1;
END IF;
ELSEIF (new.TypeId = 35) THEN
SET population = sub_pop + sub_cpop;
IF(population >= 100000) THEN
SET new.Normative = 1;
ELSE
SET new.Normative = 0;
SET new.IsNormativePositive = 1;
END IF;
ELSEIF (new.TypeId = 27) THEN
SET population = dis_pop;
IF(population > 5000) THEN
SET new.Normative = 1;
ELSE
SET new.Normative = 0;
SET new.IsNormativePositive = 1;
END IF;
ELSEIF (new.TypeId = 25) THEN
SET new.Normative = 1;
END IF;
END;
Не знаю как исправить! Ваши варианты пож-а!