MySQL Forums
Forum List  »  Stored Procedures

SQl to MYSQL
Posted by: Mauricio Pires Kalfelz MauVirtual
Date: June 30, 2018 10:32AM

I'm working on a database, I know the procedure I'm working on would be better in the application, but I need to present only the database, a friend helped me, but he did the logic in sql, I tried convert to MYSQl but it is giving error, I will show the procecure and the error, if I can I can also post the tables, thanks any help I'm desperate.

Alias ​​the idea of ​​the procedure is to analyze if the vehicle and the driver and the schedule are available to register a new trip, if they are not, back an ERROR if they are released we do the INSERT table.

CREATE PROCEDURE ADICIONAR_VIAGEM99(
IN pIDVIAGENS INT ,
IN pCIDADE VARCHAR(25) ,
IN pDATAHORAINICIO DATETIME ,
IN pDATAHORAFINAL DATETIME ,
IN pCOR VARCHAR(15) ,
IN pCEP CHAR(9) ,
IN pRUA VARCHAR(30),
IN pNUMERO VARCHAR(8) ,
IN pBAIRRO VARCHAR(25) ,
IN pESTADO CHAR(2) ,
IN pDESCRICAO VARCHAR(200),
IN pID_DADOSPESSOAS INT,
IN pID_MOTORISTA INT,
IN pID_VIATURA INT
)
BEGIN

DECLARE DisponibilidadeViatura INT;
DECLARE DisponibilidadeMotorista INT;

if exists (Select * from VIAGENS where ID_VIATURA = pID_VIATURA AND pDATAHORAINICIO between DATAHORAINICIO and DATAHORAFINAL )
set DisponibilidadeViatura = 0
else
set DisponibilidadeViatura = 1

if exists (Select * from VIAGENS where ID_MOTORISTA = pID_MOTORISTA AND pDATAHORAINICIO between DATAHORAINICIO and DATAHORAFINAL )
set DisponibilidadeMotorista = 0
else
set DisponibilidadeMotorista = 1

if (DisponibilidadeViatura = 1 and DisponibilidadeMotorista = 1)

INSERT INTO VIAGENS (IDVIAGENS, CIDADE, DATAHORAINICIO, DATAHORAFINAL, COR, CEP, RUA, NUMERO, BAIRRO, ESTADO, DESCRICAO, ID_DADOSPESSOAS, ID_MOTORISTA, ID_VIATURA)
VALUES (NULL,pCIDADE, pDATAHORAINICIO, pDATAHORAFINAL, pCOR, pCEP, pRUA, pNUMERO, pBAIRRO, pESTADO, pDESCRICAO, pID_DADOSPESSOAS, pID_MOTORISTA, pID_VIATURA);

else
Select 'Motorista ou Viatura indisponível na data/hora selecionada.' as 'Error';

END
$

error
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set DisponibilidadeViatura = 0
else
set DisponibilidadeViatura = 1

if exists (S' at line 23

Options: ReplyQuote


Subject
Views
Written By
Posted
SQl to MYSQL
297
June 30, 2018 10:32AM
106
June 30, 2018 08:52PM


Sorry, you can't reply to this topic. It has been closed.

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.