I am trying to create a Procedure in MySQL and it is returning Syntax error. Here is my code for review:
DELIMITER $$
CREATE PROCEDURE CalculaIdadeCP (IN cpcaminhaoid INT)
BEGIN
DECLARE DataEnsaio,DataMoldagem DATETIME;
/*CORPO DO PROCEDIMENTO*/
SET DataEnsaio = (
SELECT
da.DataEnsaio
FROM dadoscpconcreto AS da INNER JOIN cpcaminhao AS cp ON
da.CpCaminhaoId = cp.CPCaminhaoId
WHERE cp.CPCaminhaoId = cpcaminhaoid
);
SET DataMoldagem = (
SELECT
cp.DataMoldagem
FROM dadoscpconcreto AS da INNER JOIN cpcaminhao AS cp ON
da.CpCaminhaoId = cp.CPCaminhaoId
WHERE cp.CPCaminhaoId = cpcaminhaoid
);
IF DataEnsaio IS NOT NULL THEN
BEGIN
SET (
SELECT
da.IdadeRompimento
FROM dadoscpconcreto AS da INNER JOIN cpcaminhao AS cp ON
da.CpCaminhaoId = cp.CPCaminhaoId
WHERE cp.CPCaminhaoId = cpcaminhaoid
) = SELECT DATEDIFF(DataEnsaio,DataMoldagem);
END;
END IF;
END$$
DELIMITER;
Can anyone help me?