I used a function that is used to cover a field of a column "stakeholders" that contains names separated by commas. the objective is to compare the names with names stored in a table "speaker", it is composed of two columns: "id_équipe" (contains team name auquelle belongs intervenor name) and "nom_intervenant" (contains lists of names). .So, The objective is to compare the names with names stored in the table "intervening" .If the result is positive, we take the steps outlined in the code.
delimiter |
CREATE FUNCTION DETERMINE1234(s VARCHAR(2000)) RETURNS int(2)
DETERMINISTIC
BEGIN
DECLARE open INT;
DECLARE close INT;
DECLARE someLimit INT;
DECLARE cpt int;
DECLARE cs int;
DECLARE cm int;
DECLARE co int;
DECLARE str VARCHAR(255);
DECLARE toFind VARCHAR(2000);
SET open = 1;
SET close = 1;
SET cpt=0;
SET cs=0;
SET cm=0;
SET co=0;
SET toFind = s ;
SET someLimit = 5;
SET str ='';
WHILE close > 0 and open > 0 and someLimit > 0 DO
SET someLimit = someLimit -1;
SET toFind = SUBSTRING(toFind,open);
SET close = locate(',',toFind);
IF close > 2 THEN
SET str =SUBSTRING(toFind,2,close-2);
IF (Select id_equipe from intervenant where nom_intervenant=str='Deploiement Radio') OR
(Select id_equipe from intervenant where nom_intervenant=str='Optimisation Huawei')OR
(Select id_equipe from intervenant where nom_intervenant=str='Optimisation NSN') OR
(Select id_equipe from intervenant where nom_intervenant=str='Support BSS Nord') OR
(Select id_equipe from intervenant where nom_intervenant=str='Support BSS Sud') THEN SET co=1;
END IF;
IF (Select id_equipe from intervenant where nom_intervenant=str='QDF') OR
(Select id_equipe from intervenant where nom_intervenant=str='Supervision Back Office') THEN SET cs=1;
END IF;
IF (Select id_equipe from intervenant where nom_intervenant=str='Maintenance') THEN SET cm=1;
END IF;
SET toFind = SUBSTRING(toFind,close);
END IF;
END WHILE;
SET cpt=co+cs+cm;
return cpt;
END |
delimiter;
here is the sql query that I use:
update incident set groupes_intervenants=DETERMINE12(intervenants) WHERE Status like 'Closed'
the result will be stored in the column "stakeholder groups". thank you in advance.
Aucun commentaire:
Enregistrer un commentaire