1 Chronicles 18:2

And he smote Moab; and the Moabites became David’s servants, and brought gifts.

The verse stands within the extended record of David's work given in 1 Chronicles 4-26. That whole section is to be read alongside the parallel record in Samuel. Together they set out the organization and divisions of his armies and the work that he accomplished. They also display his virtues and his mistakes. Through them both God's mercy and guidance toward him are made plain.