Create PROCEDURE [dbo].[sp_Api5_VenDetalleRead]
    @numinv INT = 0,
    @coddoc INT = 0,
	@grudoc int = 0,
    @fecdocini DATE = NULL,
    @fecdocfin DATE = NULL
AS
BEGIN
    SELECT * 
    FROM vendetalle 
    WHERE 
    (@numinv = 0 OR numinv = @numinv)
    AND (@coddoc = 0 OR coddoc = @coddoc)
	 AND (@grudoc = 0 OR grudoc= @grudoc)
    AND (@fecdocini IS NULL OR @fecdocfin IS NULL OR fecdoc BETWEEN @fecdocini AND @fecdocfin)
END