أَخْبَرَنَا إِسْحَاقُ بْنُ إِبْرَاهِيمَ، قَالَ أَنْبَأَنَا سُلَيْمَانُ بْنُ حَيَّانَ، قَالَ حَدَّثَنَا يَحْيَى بْنُ سَعِيدٍ، عَنْ مُحَمَّدِ بْنِ إِبْرَاهِيمَ، عَنْ عَلْقَمَةَ بْنِ وَقَّاصٍ، عَنْ عُمَرَ بْنِ الْخَطَّابِ، عَنِ النَّبِيِّ صلى الله عليه وسلم قَالَ ‏"‏ إِنَّمَا الأَعْمَالُ بِالنِّيَّةِ وَإِنَّمَا لاِمْرِئٍ مَا نَوَى فَمَنْ كَانَتْ هِجْرَتُهُ إِلَى اللَّهِ وَرَسُولِهِ فَهِجْرَتُهُ إِلَى اللَّهِ وَرَسُولِهِ وَمَنْ كَانَتْ هِجْرَتُهُ لِدُنْيَا يُصِيبُهَا أَوِ امْرَأَةٍ يَتَزَوَّجُهَا فَهِجْرَتُهُ إِلَى مَا هَاجَرَ إِلَيْهِ ‏"‏ ‏.‏

It was narrated from 'Umar bin Al-Khattab that the Prophet said: "Actions are but by intentions, and each person will have but that which he intended. Thus, he whose emigration was for the sake of Allah and His Messenger, his emigration was for the sake of Allah and His Messenger, and he whose emigration was to achieve some worldly gain or to take some woman in marriage, his emigration was for that for which he emigrated." Translation Not Available

Book Ref: Sunan An Nisai Book 35 Hadith 3794
Web Ref:  Sunan An Nisai Vol 4 Book 35 Hadith 3825