CREATE PROCEDURE sp_Api5_FlgimpRead
    @numinv INT,
    @codsii INT,
    @coddoc INT,
    @grudoc INT
AS
BEGIN
    DECLARE @flgimp CHAR(1)
    
    SELECT @flgimp = flgimp 
    FROM venEncabezado 
    WHERE numinv = @numinv AND codsii = @codsii AND coddoc = @coddoc AND grudoc = @grudoc

    IF @flgimp = 'N'
        RETURN 0
    ELSE IF @flgimp = 'S'
        RETURN 1
    ELSE
        RETURN -1 -- Indica un estado desconocido o no esperado
END
