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

   DROP FUNCTION VERIFICA_LOCAL
GO

CREATE FUNCTION VERIFICA_LOCAL(
      @P_CDFILIAL      VARCHAR(4),
      @P_CDALMOXARIFE  VARCHAR(6),
      @P_CDLOCALESTOQ  VARCHAR(6)) RETURNS VARCHAR
AS
BEGIN
   DECLARE   @V_CDLOCALESTOQ   VARCHAR(6);

   SELECT @V_CDLOCALESTOQ = MAX(CDLOCALESTOQ)
   FROM LOCALESTOQUE
   WHERE CDFILIAL = @P_CDFILIAL
     AND CDALMOXARIFE = @P_CDALMOXARIFE
     AND CDLOCALESTOQ = @P_CDLOCALESTOQ;

   RETURN(@V_CDLOCALESTOQ);
END

GO

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