CREATE OR REPLACE FUNCTION DIFERENCIAL_ALIQUOTA
          (P_CDFILIAL    IN NOTAFISCAL.CDFILIAL%TYPE,
           P_NRLANCTONF  IN NOTAFISCAL.NRLANCTONF%TYPE) RETURN FLOAT
AS
  V_RESULT FLOAT;
BEGIN
   SELECT SUM(VRIMPOSTONF) AS VRDIFEALIQ
   INTO V_RESULT
   FROM IMPOSTONF IP, NOTAFISCAL NF
   WHERE (NF.CDFILIAL   = P_CDFILIAL )       AND
         (NF.NRLANCTONF = P_NRLANCTONF)      AND
         (NF.IDSTATUS   IN ('A','E'))        AND
         (NF.IDENTRSAIDOP = 'E')             AND
         (IP.CDFILIAL    = NF.CDFILIAL)      AND
         (IP.NRLANCTONF  = NF.NRLANCTONF)    AND
         (IP.IDIMPOSTONF = '3')              AND
         (IP.CDIMPOSTO BETWEEN '00' AND '00');

   RETURN(V_RESULT);
END;
/
