The Messenger of Allah ﷺ said, "Whoever acquires a branch of knowledge by which the pleasure of Allah is sought, learning it only to gain some worldly advantage, will not find the fragrance of Paradise on the Day of Resurrection," meaning its scent.
حدثنا أبو بكر بن أبي شيبة حدثنا سريج بن النعمان حدثنا فليح عن أبي طوالة عبد الله بن عبد الرحمن بن معمر الأنصاري عن سعيد بن يسار
قال رسول الله ﷺ من تعلم علما مما يبتغى به وجه الله عز وجل لا يتعلمه إلا ليصيب به عرضا من الدنيا لم يجد عرف الجنة يوم القيامة يعني ريحها
Its isnad is hasan. It was narrated by Ibn Majah in the Introduction, chapter on benefiting from knowledge and acting upon it, no. 252, from Abu Bakr bin Abu Shayba with this chain, and it is also found in al-Musannaf, 8/543. Ibn Hibban graded it sahih, no. 89, as did Hakim, 1/89.