Sahih Muslim | Book 20 | Chapter 45

Narrated by It has been narrated on the authority of Umar b. al-Khattab that the Messenger of Allah (may peace be upon him)
It has been narrated on the authority of Umar b. al-Khattab that the Messenger of Allah (may peace be upon him) said: (The value of) an action depends on the intention behind it. A man will be rewarded only for what he intended. The emigration of one who emigrates for the sake of Allah and His Messenger (may peace be upon him) is for the sake of Allah and His Messenger (may peace be upon him); and the emigration of one who emigrates for gaining a worldly advantage or for marrying a woman is for what he has emigrated.

Narrated by Sufyan
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.