Sahih Muslim Book 20, Hadith Number 4693.

Chapter : The value of an action depends on the intention behind it.

It has been narrated through a different chain of transmitters on the authority of Sufyan who said that he heard ‘Umar b. al-Khattab relate (this tradition) from the Holy Prophet (may peace be upon him) while he was delivering a sermon from the pulpit.