MySQL Forums
Forum List  »  Spanish

Procedumiento
Posted by: Santiago Jaramillo
Date: January 05, 2021 09:58PM

DELIMITER $
CREATE PROCEDURE ValidaDatos( IN ID_usuario INT)
BEGIN
DECLARE totalR1 Int(2);
DECLARE totalR2 INT(2);
DECLARE totalR3 INT(2);
DECLARE totalR4 INT(2);
DECLARE totalR5 INT(2);
DECLARE totalR6 INT(2);
DECLARE totalR7 INT(2);
DECLARE totalR8 INT(2);
DECLARE totalR9 INT(2);
DECLARE totalR10 INT(2);
DECLARE totalR11 INT(2);
DECLARE totalR12 INT(2);
DECLARE totalR13 INT(2);
DECLARE totalR14 INT(2);
DECLARE totalR15 INT(2);
DECLARE totalR16 INT(2);
DECLARE totalR17 INT(2);
DECLARE totalR18 INT(2);
DECLARE totalR19 INT(2);
DECLARE totalR20 INT(2);
DECLARE TOTAL_RT INT (2);
DECLARE REST_t VARCHAR(30);
DECLARE totalS1 VARCHAR (2);
DECLARE totalS2 VARCHAR (2);
DECLARE totalS3 VARCHAR (2);
DECLARE totalS4 VARCHAR (2);
DECLARE totalS5 VARCHAR (2);
DECLARE totalS6 VARCHAR (2);
DECLARE totalS7 VARCHAR (2);
DECLARE totalS8 VARCHAR (2);
DECLARE totalS9 VARCHAR (2);
DECLARE totalS10 VARCHAR (2);
DECLARE totalS11 VARCHAR (2);
DECLARE totalS12 VARCHAR (2);
DECLARE totalS13 VARCHAR (2);
DECLARE totalS14 VARCHAR (2);
DECLARE totalS15 VARCHAR (2);
DECLARE totalS16 VARCHAR (2);
DECLARE totalS17 VARCHAR (2);
DECLARE totalS18 VARCHAR (2);
DECLARE totalS19 VARCHAR (2);
DECLARE totalS20 VARCHAR (2);
BEGIN
SELECT pregunta1 INTO totalS1
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS1 ="si" THEN
SET totalR1 = 1;
ELSEIF totalS1 ='no' THEN
SET totalR1 = 0;
END IF;
END;
BEGIN
SELECT pregunta2 INTO totalS2
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS2 ="si" THEN
SET totalR2 = 1;
ELSEIF totalS2 ='no' THEN
SET totalR2 = 0;
END IF;
END;
BEGIN
SELECT pregunta3 INTO totalS3
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS3 ="si" THEN
SET totalR3 = 1;
ELSEIF totalS3 ='no' THEN
SET totalR3 = 0;
END IF;
END;
BEGIN
SELECT pregunta4 INTO totalS4
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS4 ="si" THEN
SET totalR4 = 1;
ELSEIF totalS4 ='no' THEN
SET totalR4 = 0;
END IF;
END;
BEGIN
SELECT pregunta5 INTO totalS5
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS5 ="si" THEN
SET totalR5 = 1;
ELSEIF totalS5 ='no' THEN
SET totalR5 = 0;
END IF;
END;
BEGIN
SELECT pregunta6 INTO totalS6
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS6 ="si" THEN
SET totalR6 = 1;
ELSEIF totalS6 ='no' THEN
SET totalR6 = 0;
END IF;
END;
BEGIN
SELECT pregunta7 INTO totalS17
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS7 ="si" THEN
SET totalR7 = 1;
ELSEIF totalS7 ='no' THEN
SET totalR7 = 0;
END IF;
END;
BEGIN
SELECT pregunta8 INTO totalS8
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS8 ="si" THEN
SET totalR8 = 1;
ELSEIF totalS8 ='no' THEN
SET totalR8 = 0;
END IF;
END;
BEGIN
SELECT pregunta9 INTO totalS9
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS9 ="si" THEN
SET totalR9 = 1;
ELSEIF totalS9 ='no' THEN
SET totalR9 = 0;
END IF;
END;
BEGIN
SELECT pregunta10 INTO totalS10
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS10 ="si" THEN
SET totalR10 = 1;
ELSEIF totalS10 ='no' THEN
SET totalR10 = 0;
END IF;
END;
BEGIN
SELECT pregunta11 INTO totalS11
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS11 ="si" THEN
SET totalR11 = 1;
ELSEIF totalS11 ='no' THEN
SET totalR11 = 0;
END IF;
END;
BEGIN
SELECT pregunta12 INTO totalR12
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS12 ="si" THEN
SET totalR12 = 1;
ELSEIF totalS12 ='no' THEN
SET totalR12 = 0;
END IF;
END;
BEGIN
SELECT pregunta13 INTO totalS13
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS13 ="si" THEN
SET totalR13 = 1;
ELSEIF totalS13 ='no' THEN
SET totalR13 = 0;
END IF;
END;
BEGIN
SELECT pregunta14 INTO totalS14
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS14 ="si" THEN
SET totalR14 = 1;
ELSEIF totalS14 ='no' THEN
SET totalR14 = 0;
END IF;
END;
BEGIN
SELECT pregunta15 INTO totalS15
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS15 ="si" THEN
SET totalR15 = 1;
ELSEIF totalS15 ='no' THEN
SET totalR15 = 0;
END IF;
END;
BEGIN
SELECT pregunta16 INTO totalS16
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS16 ="si" THEN
SET totalR16 = 1;
ELSEIF totalS16 ='no' THEN
SET totalR16 = 0;
END IF;
END;
BEGIN
SELECT pregunta17 INTO totalS17
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS17 ="si" THEN
SET totalR17 = 1;
ELSEIF totalS17 ='no' THEN
SET totalR17 = 0;
END IF;
END;
BEGIN
SELECT pregunta18 INTO totalS18
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS18 ="si" THEN
SET totalR7 = 1;
ELSEIF totalS18 ='no' THEN
SET totalR18 = 0;
END IF;
END;
BEGIN
SELECT pregunta19 INTO totalS19
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS19 ="si" THEN
SET totalR19 = 1;
ELSEIF totalS19 ='no' THEN
SET totalR7 = 0;
END IF;
END;
BEGIN
SELECT pregunta20 INTO totalS20
FROM cuestionario1
WHERE id=ID_usuario;
IF totalS20 ="si" THEN
SET totalR20 = 1;
ELSEIF totalS20 ='no' THEN
SET totalR20 = 0;
END IF;
END;
BEGIN
SET TOTAL_RT = totalR1+totalR2+totalR3+totalR4+totalR5+totalR6+totalR7+totalR8+totalR9+totalR10+totalR11+totalR12+totalR13+totalR14+totalR15+totalR16+totalR17+totalR18+totalR19+totalR20;
IF TOTAL_RT => 7 THEN
SET REST_t = 'NECESITA ATENCION MEDICA';
ELSEIF TOTAL_RT < 7 THEN
SET REST_t = 'NORMAL';
INSERT INTO RTEST1(id,resultado)
VALUES(ID_usuario,REST_t);
END;
END$
TENGO ESTE PROCEDIMIENTO PARA UNA ENCUESTA DONDE LAS RESPUESTAS SON DE "SI Y NO" me lo plantie de esta forma para darle valor de 1 a "si" y 0 a "no" la cuestion es que me marca erro en mi suma de valores en la fila donde sumo todas las variables almacenadas de los valores de las respuestas alguien me podria orientar si esta bien la sintaxis o si hay otra forma correcta de programar el procedimiento GRACIAS

Options: ReplyQuote


Subject
Views
Written By
Posted
Procedumiento
136
January 05, 2021 09:58PM
26
January 06, 2021 12:11AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.