"The Messenger of Allah said: 'Whoever acquires knowledge by which the pleasure of Allah is sought, but he only acquires it for the purpose of worldly gain, will not smell the fragrance of Paradise on the Day of Resurrection.'" (Hasan) Another chain with similar wording.
قَالَ رَسُولُ اللَّهِ ﷺ مَنْ تَعَلَّمَ عِلْمًا مِمَّا يُبْتَغَى بِهِ وَجْهُ اللَّهِ لاَ يَتَعَلَّمُهُ إِلاَّ لِيُصِيبَ بِهِ عَرَضًا مِنَ الدُّنْيَا لَمْ يَجِدْ عَرْفَ الْجَنَّةِ يَوْمَ الْقِيَامَةِ يَعْنِي رِيحَهَا قَالَ أَبُو الْحَسَنِ أَنْبَأَنَا أَبُو حَاتِمٍ حَدَّثَنَا سَعِيدُ بْنُ مَنْصُورٍ حَدَّثَنَا فُلَيْحُ بْنُ سُلَيْمَانَ فَذَكَرَ نَحْوَهُ