When an attorney is a witness for his client upon any trial except as to merely formal matters such as the attestation or custody of an instrument or the like, he shall not further participate in such trial. This section shall not apply when such attorney's testimony is offered in answer to evidence received on behalf of the other party and it shall appear to the satisfaction of the court that such attorney had no reason to anticipate the necessity of his being a witness. Neither shall this section apply to state's attorneys and the attorney general and their deputies when engaged in the discharge of official duties.
SDCL 19-1-3