'Like his deeds' means just like his deeds. And what is 'below'? He collects from what is his own. What does the Holy One, blessed be He, do when a person is involved in a sin and deserving of death?

He waits until he marries and has children, and then He takes one of his sons in place of that sin that he committed. In this way, the Holy One, blessed be He, collects from his own. There is an even greater kindness than this: 'To you, O Lord, belongs kindness.' Rabbi Nehemiah says: What is 'like his deeds'?

There is a person who thinks to commit a sin, but does not do it, and the Holy One, blessed be He, does not record it until he actually commits it. However, if he thinks to do a good deed and is forced not to do it, the Holy One, blessed be He, records it as if he had done it. And you have learned from David, who was pained that he could not build the Temple, as it is said: 'Remember, O Lord, for David's sake, all the hardships he endured; how he swore an oath to the Lord' (Psalm 132:1-2).

'If only I could come to dwell in the tent of the Lord!' (1 Chronicles 22:14) And yet, with all his troubles, he prepared for the house of his God." And so it says (2 Samuel 7:1) "And it came to pass, when the king sat in his house, and the Lord had given him rest round about," he began to ponder in his heart and said (2 Samuel 7:2), "See now, I dwell in a house of cedar, but the ark of God dwelleth within curtains."

Nathan the prophet said to him, "Did it not come up into the heart of the Lord to seek a man after His own heart?" (1 Samuel 13:14). It did not come up in your heart. Immediately, God revealed to him through Nathan, as it is written (2 Samuel 7:4-5), "And it came to pass that night, that the word of the Lord came unto Nathan, saying, Go and tell my servant David, Thus saith the Lord, Shalt thou build me an house for me to dwell in?"

And it is written in another place (1 Chronicles 17:4), "Thou shalt not build me an house to dwell in." How can these two verses be reconciled? "Thou shalt not build me an house" means that it is not you who will build a house for Me, but your son Solomon will build it. "Shalt thou build me an house for me to dwell in?" means that the house will be called by your name, as it is written (Psalm 30:1), "A Psalm and Song at the dedication of the house of David."

"And because you have shed much blood, I cannot allow you to build it, but only in the name of the Lord, since you have suffered. When David heard this, he became afraid and said, 'I have been disqualified from building the Temple.' Rabbi Yehuda bar Elai said to him, 'The Holy One, blessed be He, said to him, "Do not be afraid. Your bloodshed is like that of a deer or a gazelle before Me, as it is written of them (Deuteronomy 12:24), 'You shall pour it on the ground like water.' " David said to Him, "If so, why can't I build it?"

He replied to him, "It is known and revealed before Me that the Israelites are destined to sin, and I vent My anger on it, and Israel will be saved. And if you build it, it will be established forever and will never be destroyed." David said to Him, "But isn't it beautiful?" He replied, "It is better that I vent My anger and destroy it, and they will be saved."

This is what is written (Lamentations 2:4), "He has aimed His bow like an enemy." David said to Him, "And even though You are not building it, since You have considered it to be built in Your name, I will call it by Your name," as it is written (Psalm 30:1), "A psalm; a song for the dedication of the house. Of David." It does not say, "Of Solomon," but "Of David," to teach you that whoever intends to perform a commandment but is prevented from doing so, the Holy One, blessed be He, credits him as if he had performed it."