drop PROCEDURE if EXISTS sp_alm_sendGuiaRemision_consult;
DELIMITER $$
CREATE  PROCEDURE `sp_alm_sendGuiaRemision_consult`(IN `idP` INT)
    NO SQL
BEGIN

-- SELECT status 
-- FROM tec_send_invoice_gr 
-- WHERE referral_guide_id = idP and estado= 1;
SELECT status 
FROM tec_send_invoice_gr 
WHERE referral_guide_id = idP and estado= 1
UNION
SELECT 0 as status
FROM DUAL
WHERE NOT EXISTS (
SELECT status 
FROM tec_send_invoice_gr 
WHERE referral_guide_id = idP and estado= 1
    );


END$$
DELIMITER ;