IF OBJECT_ID('dbo.sp_fco_baja_fantasmas') IS NOT NULL
    DROP PROCEDURE dbo.sp_fco_baja_fantasmas
GO
CREATE PROCEDURE dbo.sp_fco_baja_fantasmas
(
    @pch_compania char(4), 
    @pch_trabajador char(10)
)
AS
BEGIN
    IF NOT EXISTS (SELECT 1 FROM fco_fantasmas
               WHERE compania = @pch_compania
                 AND RTRIM(LTRIM(trabajador)) = RTRIM(LTRIM(@pch_trabajador)))
    BEGIN
        RAISERROR ('El registro a eliminar en [fco_fantasmas] no existe', 16, 1)
        RETURN
    END

    DELETE fco_fantasmas
    WHERE compania = @pch_compania
     AND RTRIM(LTRIM(trabajador)) = RTRIM(LTRIM(@pch_trabajador))
END
GO
GRANT EXECUTE ON dbo.sp_fco_baja_fantasmas TO PUBLIC
GO
