salix/db/routines/srt/procedures/expeditionLoading_add.sql

32 lines
654 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `srt`.`expeditionLoading_add`(vExpeditionFk INT, vBufferFk INT)
BEGIN
DECLARE vMessage VARCHAR(50) DEFAULT '';
IF (SELECT COUNT(*) FROM srt.buffer WHERE id = vBufferFk) = 0 THEN
SET vMessage = 'Buffer incorrecto';
END IF;
IF (SELECT COUNT(*) FROM srt.expedition WHERE id = vExpeditionFk) = 0 THEN
SET vMessage = 'Expedición no existe';
END IF;
IF LENGTH(vMessage) = 0 THEN
REPLACE srt.expeditionLoading (expeditionFk, bufferFk)
VALUES (vExpeditionFk, vBufferFk);
SET vMessage = 'Registro añadido';
END IF;
SELECT vMessage;
END$$
DELIMITER ;