1 ChroniclesChapter 19

Some time later Nahash king of the Ammonites died, and his son became king in his place.
David said, "I will show kindness to Hanun son of Nahash, because his father showed kindness to me." So David sent messengers to console him over his father. But when David's servants came to Hanun in the land of the Ammonites to console him,
the Ammonite commanders said to Hanun, "Do you really think David is honoring your father by sending you men to console you? Haven't his servants come to you to explore the land, to overthrow it, and to spy it out?"
So Hanun seized David's servants, shaved them, cut their garments in two at the hips, and sent them away.
When word came to David about the men, he sent messengers to meet them, for the men were deeply humiliated. The king said, "Stay in Jericho until your beards have grown back, and then return."
When the Ammonites saw that they had made themselves odious to David, Hanun and the Ammonites sent a thousand talents of silver to hire chariots and horsemen from Aram Naharaim, Aram Maacah, and Zobah.
They hired thirty-two thousand chariots, along with the king of Maacah and his troops, who came and camped near Medeba. The Ammonites also mustered from their cities and came out to fight.
When David heard of it, he sent Joab out with the whole army of fighting men.
The Ammonites marched out and drew up in battle formation at the entrance to the city, while the kings who had come took up positions by themselves in the open field.
Joab saw that he faced battle lines both in front of him and behind, so he chose some of the best troops in Israel and deployed them against the Arameans.
The rest of the men he put under the command of his brother Abishai, and they were deployed against the Ammonites.
Joab said, "If the Arameans are too strong for me, then you are to come to my rescue; but if the Ammonites are too strong for you, then I will rescue you.
Be strong, and let us fight bravely for our people and for the cities of our God. And may the LORD do what is good in his sight."
Then Joab and the troops with him advanced to attack the Arameans, and they fled before him.
When the Ammonites saw that the Arameans were fleeing, they too fled before his brother Abishai and withdrew into the city. So Joab returned to Jerusalem.
When the Arameans saw that they had been routed by Israel, they sent messengers and brought out the Arameans from beyond the Euphrates, with Shophach the commander of Hadadezer's army at their head.
When David was told of it, he gathered all Israel, crossed the Jordan, advanced against them, and drew up his lines to meet them. David formed his battle line against the Arameans, and they fought against him.
But the Arameans fled before Israel, and David killed seven thousand of their charioteers and forty thousand foot soldiers. He also killed Shophach the commander of their army.
When the vassals of Hadadezer saw that they had been defeated by Israel, they made peace with David and became subject to him. And the Arameans were no longer willing to help the Ammonites.