IF EXISTS (SELECT * FROM SYSOBJECTS O, SYSUSERS U
           WHERE O.NAME = 'VALOR_MAOIR_NF' AND
                 TYPE = 'FN' 		      AND
	              U.UID = O.UID           AND
	              U.NAME = USER)
DROP FUNCTION VALOR_MAOIR_NF
GO

CREATE FUNCTION VALOR_MAOIR_NF
   (@P_VRNOTAFISC VARCHAR(20)) RETURNS VARCHAR
AS
BEGIN
DECLARE  @V_CDVALOR  NUMERIC;

   IF ((@P_VRNOTAFISC >= '50,01') AND (@P_VRNOTAFISC <= '100,00')) BEGIN
      SET @V_CDVALOR = '10';
   END;

   IF ((@P_VRNOTAFISC >= '100,01') AND (@P_VRNOTAFISC <= '200,00')) BEGIN
      SET @V_CDVALOR = '11';
   END;

   IF ((@P_VRNOTAFISC >= '100,01') AND (@P_VRNOTAFISC <= '200,00')) BEGIN
      SET @V_CDVALOR = '12';
   END;

   IF ((@P_VRNOTAFISC >= '200,01') AND (@P_VRNOTAFISC <= '300,00')) BEGIN
      SET @V_CDVALOR = '13';
   END;

   IF ((@P_VRNOTAFISC >= '300,01') AND (@P_VRNOTAFISC <= '400,00')) BEGIN
      SET @V_CDVALOR = '14';
   END;

   IF ((@P_VRNOTAFISC >= '400,01') AND (@P_VRNOTAFISC <= '500,00')) BEGIN
      SET @V_CDVALOR = '15';
   END;

   IF ((@P_VRNOTAFISC >= '500,01') AND (@P_VRNOTAFISC <= '1000,00')) BEGIN
      SET @V_CDVALOR = '16';
   END;

   IF (@P_VRNOTAFISC >= '1000,01') BEGIN
      SET @V_CDVALOR = '17';
   END;

   RETURN(@V_CDVALOR);
END
GO


-- VERSAO --
EXEC ATUVEROBJ 'VALOR_MAOIR_NF','5.05.008';
GO

