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

   DROP FUNCTION VERIFICA_ALMOX
GO

CREATE FUNCTION VERIFICA_ALMOX(
      @P_CDFILIAL      VARCHAR(4),
      @P_CDALMOXARIFE  VARCHAR(6)) RETURNS VARCHAR
AS
BEGIN
   DECLARE   @V_CDALMOXARIFE   VARCHAR(6);

   SELECT @V_CDALMOXARIFE = MAX(CDALMOXARIFE)
   FROM ALMOXARIFADO
   WHERE CDFILIAL = @P_CDFILIAL
     AND CDALMOXARIFE = @P_CDALMOXARIFE;

   RETURN(@V_CDALMOXARIFE);
END
GO

-- VERSAO --
EXEC ATUVEROBJ  'VERIFICA_ALMOX','5.09.001';
GO
