2 Samuel 8:2

And he smote Moab, and measured them with a line, casting them down to the ground; even with two lines measured he to put to death, and with one full line to keep alive. And so the Moabites became David’s servants, and brought gifts.

The verse stands within the history told in 2 Samuel 3 through 20, following the capture of the city of Zion, the defeat of the Philistines, the bringing up of the ark, the plan to build a temple, and the prayer and thanksgiving, and coming before the kindness to Mephibosheth son of Jonathan and the war with Ammon and Syria. It belongs to the account of the rise of David's kingdom, which shows God's providence in building up the Israelite kingdom. It records one of David's victories over the surrounding kingdoms that brought Israel rest from its enemies, subdued his enemies, and greatly enlarged Israel's dominion.

The victories belong to the same period as the battles described in chapter 10. David's defeat of Moab made the Moabites his servants and tributary, bringing gifts and rendering labor. His dominion extended eastward to the Euphrates, and he garrisoned Damascus after taking control of the Syrian kingdom, and these conquests formed part of Israel's prosperity and power before his later sin.

The measuring with lines means David assigned the Moabites to servitude and suitable work rather than putting them to death. The treatment of the Ammonite captives in 2 Samuel 12:31 is explained in the same way as assigning them work as they passed before him on a paved area, since the word translated under can mean with when used with a tool or instrument and pass through the brick-kiln can mean passing by or before a paved area. The rest from surrounding enemies made it possible for David to turn his attention to a permanent house for God's ark. The lesson is to focus on the results of these victories rather than dwell on the slaughter, trusting God's wisdom and justice when the reasons for events are not fully understood.