Language:
كتاب كفارات الأيمان
84  
Expiation for Unfulfilled Oaths
(9)
Chapter: To say: “In sha’ Allah” while taking an oath
(9)
باب الاِسْتِثْنَاءِ فِي الأَيْمَانِ
Sahih al-Bukhari 6720

Narrated Abu Huraira:

(The Prophet) Solomon said, "Tonight I will sleep with (my) ninety wives, each of whom will get a male child who will fight for Allah's Cause." On that, his companion (Sufyan said that his companion was an angel) said to him, "Say, "If Allah will (Allah willing)." But Solomon forgot (to say it). He slept with all his wives, but none of the women gave birth to a child, except one who gave birth to a halfboy. Abu Huraira added: The Prophet (ﷺ) said, "If Solomon had said, "If Allah will" (Allah willing), he would not have been unsuccessful in his action, and would have attained what he had desired." Once Abu Huraira added: Allah apostle said, "If he had accepted."

حَدَّثَنَا عَلِيُّ بْنُ عَبْدِ اللَّهِ، حَدَّثَنَا سُفْيَانُ، عَنْ هِشَامِ بْنِ حُجَيْرٍ، عَنْ طَاوُسٍ، سَمِعَ أَبَا هُرَيْرَةَ، قَالَ قَالَ سُلَيْمَانُ لأَطُوفَنَّ اللَّيْلَةَ عَلَى تِسْعِينَ امْرَأَةً، كُلٌّ تَلِدُ غُلاَمًا يُقَاتِلُ فِي سَبِيلِ اللَّهِ‏.‏ فَقَالَ لَهُ صَاحِبُهُ ـ قَالَ سُفْيَانُ يَعْنِي الْمَلَكَ ـ قُلْ إِنْ شَاءَ اللَّهُ‏.‏ فَنَسِيَ، فَطَافَ بِهِنَّ، فَلَمْ تَأْتِ امْرَأَةٌ مِنْهُنَّ بِوَلَدٍ، إِلاَّ وَاحِدَةٌ بِشِقِّ غُلاَمٍ‏.‏ فَقَالَ أَبُو هُرَيْرَةَ يَرْوِيهِ قَالَ ‏"‏ لَوْ قَالَ إِنْ شَاءَ اللَّهُ، لَمْ يَحْنَثْ وَكَانَ دَرَكًا فِي حَاجَتِهِ ‏"‏‏.‏ وَقَالَ مَرَّةً قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏"‏ لَوِ اسْتَثْنَى ‏"‏‏.‏ وَحَدَّثَنَا أَبُو الزِّنَادِ عَنِ الأَعْرَجِ مِثْلَ حَدِيثِ أَبِي هُرَيْرَةَ‏.‏
Reference : Sahih al-Bukhari 6720
In-book reference : Book 84, Hadith 13
USC-MSA web (English) reference : Vol. 8, Book 79, Hadith 711
  (deprecated numbering scheme)