If the defendant prevails in the action or if the action be discontinued, the defendant shall have judgment for the damages sustained by the defendant for any damages to the defendant's property by reason of the taking and detention or sale thereof.
N.D.C.C. § 32-08.1-19