When it is necessary that a person imprisoned by the department be brought before any court, or that a person imprisoned in a county jail be brought before a court in another county, an order may be made for that purpose by the court and executed by the sheriff of the county where the order is made.
A.R.S. § 31-225