Immanuel Kant said this quote

An action done from duty has its moral worth, not in the purpose to be attained by it, but in the maxim according with which it is decided upon; it depends therefore, not on the realization of the object of action, but solely on the principle of volition in accordance with which, irrespective of all objects of the faculty of desire, the action has been performed.