Syntax error in Mysql database

Asked

Viewed 137 times

0

I am trying to create a Procedure in Mysql and is returning Syntax error. Follow my code for analysis:

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 someone help me ?

  • Continue with the mistake !

  • Paste the code there for me to put here in my SQL.

  • What does that mean IF DataEnsaio ? You’re giving a SET on what ? And that = SELECT at the end of it ?

  • I am giving a Set of the difference of the two Dates on the return of the SELECT (da.Idaderompimento) . But I only do this if the Date is not null

1 answer

0

Try to separate the $$ of END and the ; of DELIMITER at the end of the instruction.

END $$
DELIMITER ;

Without the space you say that these characters are part of the command and this may be causing the error.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.