IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'dbo.CF_AR_MEGATLON_WS_Token_Acceso_Token_Activo') 
                   and type = 'FN')
BEGIN
    DROP FUNCTION dbo.CF_AR_MEGATLON_WS_Token_Acceso_Token_Activo 
END
GO

CREATE FUNCTION dbo.CF_AR_MEGATLON_WS_Token_Acceso_Token_Activo() 
RETURNS VARCHAR(2000)
AS
BEGIN
DECLARE @TokenActivo VARCHAR(2000)

SET @TokenActivo = ISNULL(	(SELECT ISNULL(Token, '') 
							FROM AR_MEGATLON_WS_Token_Acceso 
							WHERE 
							Fecha_Expiracion > GETDATE())
						,'')

RETURN ISNULL(@TokenActivo, '')
END
