It is narrated from Sayyiduna Abu Hurayrah (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said: "Whatever purpose a person comes to the mosque for, that is his share."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 4990