No person is obliged to attend as a witness in a criminal action or proceeding in this state before a court or magistrate outside of the county in which the person resides or is served with the subpoena, unless the committing magistrate before whom the defendant is brought, or the judge of the court in which the offense is triable, or a judge of the district court, or a judge of the supreme court, upon an affidavit of the state's attorney or prosecutor, or of the defendant, or the defendant's counsel, stating that the affiant believes the evidence of the witness is material, and the witness's attendance at the examination or trial necessary, shall endorse upon the subpoena an order for the attendance of the witness.
N.D.C.C. § 31-01-14