Daniel W. Harr appeals from a judgment convicting him of three counts of possession of a firearm by a felon and sentencing him to a total of five years in prison, to be served "consecutive" to his § 971.17, Stats., commitment to the Mendota Mental Health Institution (Mendota), which resulted from an *586unrelated criminal case in which he was adjudged not guilty by reason of mental disease or defect (NGI). He argues that (1) a criminal sentence cannot lawfully be imposed to run consecutive to an NGI commitment; and (2) he is entitled to time-served credit on his sentence for thirty days spent in the county jail on cash bail on this and the unrelated charge, as well as 145 days from the time of his NGI commitment until the imposition of the sentence in this case.
We conclude that, under the plain language of applicable statutes, the trial court lacked authority to impose a prison sentence consecutive to a §971.17, STATS., commitment, and we therefore reverse and remand to the trial court for resentencing. We also conclude that, while Harr is entitled to credit of an additional thirty days on his sentence for time spent in jail pursuant to unsatisfied cash bail, he is not entitled to credit for any period of time after his NGI commitment in the other case.
I. The Sentence
Harr was arrested in Sauk County in April 1995 on several firearms charges. While the charges were pending in the trial court, he was adjudged NGI in an unrelated criminal prosecution for battery to a peace officer, and, on February 1, 1996, he was committed to the Department of Health and Social Services (DHSS) for institutional care for a period not to exceed forty months. DHSS placed him at Mendota.
Several months later, Harr pleaded no contest to three counts of possession of illegal firearms. On June 25,1996, the trial court sentenced him to three years in prison on the first count, stating that the sentence was to be "consecutive to your release from the commitment to Mendota Mental Health Institution." He was *587sentenced to two years (consecutive) on the second count and two years (concurrent) on the third. Harr appealed his sentence, arguing that the court has no statutory authority to impose a criminal sentence consecutive to a § 971.17, Stats., commitment.
Trial courts have only such sentencing powers as the legislature has granted. Grobarchik v. State, 102 Wis. 2d 461, 467, 307 N.W.2d 170, 174 (1981). Section 973.15(2), Stats., which authorizes imposition of consecutive and concurrent sentences, provides in pertinent part as follows: "(a) Except as provided in par. (b), the court may impose as many sentences as there are convictions and may provide that any such sentence be concurrent with or consecutive to any other sentence imposed at the same time or previously." (Emphasis added.)
"Sentence" is defined as " 'the judgment of a court by which the court imposes the punishment or penalty provided by statute for the offense upon the person found guilty.'" Grobarchik, 102 Wis. 2d at 468, 307 N.W.2d at 174 (quoted source omitted). Harr's NGI commitment is, plainly, not a sentence within the meaning of that definition. He has not been convicted or "found guilty" of a crime.1 There is, in short, no underlying "sentence" upon which to add a consecutive term of imprisonment.
In State v. Szulczewski, 209 Wis. 2d 1, 561 N.W.2d 781 (Ct. App. 1997), the defendant had injured a fellow resident at the institution where he had been placed *588after commitment to DHSS pursuant to an NGI adjudication. He was charged with battery, entered a plea of not guilty, and was tried and convicted of the offense. Id. at 4-5, 561 N.W.2d at 783. He was sentenced to five years in prison, to be served "concurrent with [his] Not Guilty by Insanity commitment," and the trial court ordered his immediate transfer to the Department of Corrections for placement within the prison system. He argued on appeal that the court lacked authority to order the prison sentence to commence immediately because he had not been discharged from his NGI commitment. His position was, in essence, that service of his criminal sentence must await completion of his NGI commitment.
We rejected the argument. First, citing State v. Woods, 173 Wis. 2d 129, 137, 496 N.W.2d 144, 147-48 (Ct. App. 1992) — where we held that an adult sentence could not run consecutive to a juvenile disposition because such a disposition is not a "sentence" — we concluded in Szulczewski that the applicable statutes did not give the trial court authority to impose a sentence "concurrent" to an NGI commitment. Szulczewski, 209 Wis. 2d at 6, 561 N.W.2d at 783.2 We went on to say, however, that because § 973.15(1), STATS., unambiguously requires sentences to "commence at noon on the day of sentence," the trial court properly directed the defendant's criminal sentence to begin immediately.
*589The State urged us to "harmonize" §§ 971.17 and 973.15, Stats., and rule that Szulczewski's prior NGI commitment constituted "legal cause" for which a sentence may be stayed under § 973.15(8)(a)l — thus permitting trial courts to determine on a case-by-case basis whether to impose a sentence immediately, or to stay it pending expiration of a prior NGI commitment. We declined to do so, noting that "a sentence cannot be ordered consecutive to an NGI commitment." Szulczewski, 209 Wis. 2d at 7, 561 N.W.2d at 784.3
We next consider the appropriate remedy. In his argument to the trial court at the sentencing hearing, defense counsel stressed that Harr had "serious mental health problems," which were being "addressed" at Mendota, and pointed out that the "public-protection" sentencing objective would be met by Harr's continued confinement at Mendota for the remainder of his commitment.4 The trial court proceeded to sentence Harr, offering no explanation for its decision to make the prison sentence "consecutive" to his NGI commitment. Then, during argument on the appropriate amount of time-served credit, defense *590counsel asked the court to reconsider the "consecutive" nature of the sentence, pointing out that because Harr's NGI commitment was not a "sentence," there was no authority to impose another sentence consecutive to it, and that, as a result, the three-year prison sentence "would have to begin forthwith." The court replied that "if that were the case," it would "consider modifying [the] entire structure of the sentence," and stated that it would entertain "a motion in that regard." Counsel said he would leave the matter to "appellate counsel," and nothing further appears in the trial court record on the subject.
It is apparent from the record and the trial court's remarks that, whatever reason or purpose the court may have had for structuring Harr's sentence the way it did, that purpose has been frustrated by our ruling that the sentence imposed was not consistent with applicable law and that, under Szulczewski, Harr's prison sentence would have to commence immediately.
In Grobarchik, the supreme court recognized that, "[a]s a general rule, resentencing is the proper method to correct a sentence which is not in accord with the law." Id. at 470, 307 N.W.2d at 175. "A sentencing proceeding is not a game, and when a trial judge mistakenly fashions a criminal disposition that is not authorized in the law, the result should not be a windfall to the defendant." Id. at 471, 307 N.W.2d at 176. Neither should it be an undue detriment to the defendant or a windfall to the State, and we therefore remand to the trial court for resentencing.
II. Sentence Credit
Harr became subject to cash bail on the firearms charges on January 2, 1996, and because he was *591unable to post bail, he was detained at the Sauk County jail. During this time he was also subject to cash bail on the battery charge that eventually resulted in the NGI commitment. He remained in jail until he was adjudged NGI and committed to Mendota in the other case on February 1. As indicated, he was not sentenced on the firearms charges until June 25, 1996, and he argues that he is entitled to credit on the firearms sentence from January 2 to June 24. The trial court denied his request without explanation, apparently acquiescing in the prosecutor's argument that because Harr was also being held in the county jail from January 2 to February 1 on unsatisfied cash bail on the battery charge — and from February 1 onward pursuant to his NGI commitment on that charge — he was not in "custody in connection with the course of conduct for which [the] sentence was imposed" in the firearms case, within the meaning of § 973.155(l)(a), Stats., during that time.
Harr bases his argument on State v. Demars, 119 Wis. 2d 19, 26, 349 N.W.2d 708, 711-12 (Ct. App. 1984), citing the case for the proposition that "custody" within the meaning of § 973.155, STATS., attaches with the setting of cash bail and continues until sentencing or until the conditions of bail are met, even if there is "another independent and unrelated basis for custody." Specifically, he argues that, even though he was in jail and later confined at Mendota, as a result of "process" in the unrelated battery case, the fact that he was also subject to unsatisfied cash bail on the instant firearms charges during that time satisfies the "custody in connection with the course of conduct for which sentence was imposed" language of § 973.155.
The defendant in Demars was initially jailed on February 9, 1983, on charges filed in Fond du Lac *592County. Id. at 21, 349 N.W.2d at 709. He was on probation from other charges at the time and a probation hold was placed against him on the date of his arrest. On February 22, charges were filed against him in Winnebago County and, shortly thereafter, the Winnebago County sheriff issued a "detainer" to Fond du Lac County requesting that Demars be detained in Fond du Lac if he should post bail and his probation hold were lifted. On May 2, the defendant was taken to Winnebago County for his initial appearance on the Winnebago County charges and cash bail was set. He pleaded guilty to the Winnebago County charges and was sentenced on May 18. Id. at 22, 349 N.W.2d at 710. He requested credit for the eighty-three days between the filing of the "detainer" and the date of his sentence, and the trial court denied the request.
We affirmed, concluding that his presentence confinement from the date of the filing of the "detainer" to sentencing did not constitute "custody in connection with the course of conduct for which sentence was imposed" under § 973.155, Stats. We reasoned that: (1) "custody" as used in the statute "must necessarily result from the occurrence of a legal event, process or authority which occasions, or is related to, confinement on the charge for which the defendant is ultimately sentenced";5 and (2) that event did not occur in Demars's case until May 2, when he was taken to Winnebago County from the Fond du Lac County jail *593for arraignment on the Winnebago County charges and cash bail was set. Demars, 119 Wis. 2d at 26, 349 N.W.2d at 712. "Therefore," we said, "Demars' custody from May 2 . . . until his sentencing on May 18 . . . related to the 'course of conduct for which sentence was imposed' within the meaning of [the statute]," and we allowed sixteen days' credit from May 2 to the May 18 sentencing date. Id. at 26-27, 349 N.W.2d at 712.
In arriving at that conclusion, we acknowledged that the cases to which we had been referred all showed "the presence of a legal event, process or authority which occasioned at least in part, the custody of the defendant relative to the charge for which he was ultimately sentenced." Id. at 25-26, 349 N.W.2d at 711 (emphasis added).6 The italicized language does suggest, as Harr argues, that as long as he was subject to cash bail on the firearms charges during the time he was jailed in Sauk County and confined at Mendota on the unrelated charges, the cash bail must be considered to have "at least in part" occasioned his custody during all the time it remained unsatisfied.
In a later case — State v. Gavigan, 122 Wis. 2d 389, 362 N.W.2d 162 (Ct. App. 1984) — however, we reached a different result on substantially similar facts, and the supreme court expressly upheld our reasoning, adopting it verbatim as the court's own precedent. Gavigan was arrested and charged with fleeing an officer, a misdemeanor, on September 16, 1982. Id. at *594390, 362 N.W.2d at 163. The following day, he was charged with felony robbery and was unable to post cash bail. On October 24, thirty-nine days after his arrest for fleeing, he pleaded guilty and was sentenced to six months in jail on that charge. On February 9, 1983, he was convicted and sentenced to three years in prison on the robbery charge. Id. at 391, 362 N.W.2d at 164. He received credit on the sentence for the thirty-nine days between his arrest on September 16 and his sentencing on October 24 for fleeing, and he requested an additional 107 days' credit for the time served between October 24 (when he pleaded to the fleeing charge and was sentenced to the county jail) and February 9 (when he was found guilty of robbery and sent to prison).
On appeal Gavigan argued that, after October 24, he was in custody "partially" because of his failure to make bail on the robbery charge and partially because of his fleeing conviction. As a result, he claimed his custody was " 'in connection with' a course of conduct (robbery) for which sentence was imposed." Id. at 393, 362 N.W.2d at 165. We rejected the argument, stating:
Once Gavigan pleaded guilty to and was sentenced on the fleeing charge, he was in custody solely for his conviction on that misdemeanor and not, as he argues, partly because of his failure to make bail on the robbery charge. When he began serving the misdemeanor sentence on October 24, Gavigan no longer was eligible to be released on bail for the robbery charge. Thus, we reject his argument that after October 24 his custody was "in connection with" the robbery charge because the custody was not due to his failure to make bail on the robbery charge, but was attributable solely to his misdemeanor conviction.
*595Id. at 394, 362 N.W.2d at 165.
In State v. Beets, 124 Wis. 2d 372, 380-81, 369 N.W.2d 382, 386 (1985), the supreme court quoted the above paragraph, "expressly approving]" it and "accept [ing] the . . . holding by the court of appeals as precedent for this court."7 Thus, to the extent there is a conflict or inconsistency between our decisions in Demars and Gavigan, the supreme court has resolved that conflict or inconsistency in favor of Gavigan's holding, on facts generally similar to those in the instant case. Once a defendant who is being held in custody on unsatisfied cash bail on two separate charges is convicted and sentenced on one of them, that conviction and sentence become the sole basis for custody, and sentence credit for time served pursuant *596thereto is not available on the remaining charge — even though the bail remains in effect on that charge.
In his reply brief, Harr concedes, "If [his] Section 971.17 commitment was a criminal sentence, the State's position on credit would be correct." He maintains, however, that because — as we noted above — his NGI commitment is not a sentence, the Gavigan/Beets rule is inapplicable. We disagree. In State v. Riley, 175 Wis. 2d 214, 220, 498 N.W.2d 884, 886 (Ct. App. 1993), we rejected the argument that confinement as a condition of probation was not a "sentence" within the meaning of § 973.155, Stats., pointing out that "[s]ection 973.155(1), Stats., uses the terms 'custody' and 'confinement,' not the word 'sentence,' to define the status that entitles a defendant to pre-sentence credit . . . ." We are satisfied that the same analysis applies when the confinement results from an NGI commitment.
We conclude, therefore, that Harr is not entitled to any credit on his sentence for time served after his NGI commitment on February 1, 1996, because his confinement thereafter resulted solely from the NGI adjudication in the battery case. As to credit for the time between January 2 and February 1, when he was being held in jail for his inability to satisfy the cash-bail requirements in both cases, the State maintains that the same rule should apply: that, for credit to apply in such a situation, Harr must have been held "solely because of the unsatisfied cash bail in this case." (Emphasis added.) We think otherwise.
The question comes down to this: when a defendant is being held because he or she is unable to satisfy cash-bail requirements on two or more unrelated charges — as was Harr from January 2 to February 1 — is he or she entitled to sentence credit on *597both charges? We believe the answer is yes. Gavigan was held on unsatisfied cash bail on both the principal charge and an unrelated charge, yet he received credit for the jail time — up to when a sentence was imposed on the unrelated charge. The same is true here. Harr was "in custody" within the meaning of § 973.155, Stats., with respect to the firearms charge when cash bail was imposed on January 2. And despite the fact that he was also subject to bail on the unrelated charge during this time, the custody was at least "in part" occasioned by his inability to meet the bail requirement in this case. See Demars, 119 Wis. 2d at 25-26, 349 N.W.2d at 711-12. He is, therefore, entitled to credit on his sentence for the thirty days between January 2 and his February 1 adjudication and commitment. Section 973.155.8
We therefore reverse and remand the judgment of conviction insofar as it denied Harr credit on his sentence in this case for the thirty days between January 2 and February 1, 1996. In all other respects, we affirm. Further proceedings shall be consistent with this opinion.
By the Court. Judgment affirmed in part; reversed in part and cause remanded.
In State v. Randall, 192 Wis. 2d 800, 833, 532 N.W.2d 94, 107 (1995), the supreme court characterized an NGI adjudication as an" acquittal by reason of insanity." (Emphasis added.)
In State v. Szulczewski, 209 Wis. 2d 1, 561 N.W.2d 781 (Ct. App. 1997), the State conceded that, because an NGI commitment is not a "sentence" within the meaning of § 973.15 (2), Stats., it was improper for the trial court in that case to order the battery sentence to be served "concurrent with" the commitment. Id. at 6, 561 N.W.2d at 783.
The State makes a similar "stay" argument in this case, grounded on the same authority it advanced in Szulczewski: the provisions of § 973.15(8)(a)1, Stats., permitting sentences to be stayed for "legal cause," and State v. Strohbeen, 147 Wis. 2d 566, 433 N.W.2d 288 (Ct. App. 1988), where we held that a criminal sentence could be made consecutive to incarceration for failure to pay a fine. Id. at 572-73, 433 N.W.2d at 289-90. As we did in Szulczewski, we decline "the State's invitation to declare that the existence of a prior commitment under § 971.17 . . . constitutes 'legal cause' for staying a criminal sentence." Szulczewski, 209 Wis. 2d at 8, 561 N.W.2d at 784.
As counsel acknowledges, the committing court could shorten the forty-month maximum commitment.
Harr correctly points out that in State v. Demars, 119 Wis. 2d 19, 349 N.W.2d 708 (Ct. App. 1984), we recognized that an unsatisfied cash bail constitutes "custody" with respect to the charge(s) for which it is imposed, "without consideration as to whether the subject chooses to meet the conditions which would obtain his release or takes efforts to that end." Id. at 26-27, 349 N.W.2d at 712.
The "at least in part" language apparently came from the criminal instructions committee's interpretive commentary on § 973.155, STATS., defining the statutory phrase "in connection with" as meaning that the custody must be, "at least in part, the result of a legal status ... stemming from the course of conduct for which sentence is being imposed." Wis J I—CRIMINAL SM-34A at 6.
In State v. Beets, 124 Wis. 2d 372, 369 N.W.2d 382 (1985), the defendant, who was on probation on drug charges, was arrested for burglary on June 26, 1982. Because he had failed to report to probation authorities in the weeks prior to his arrest, he was also in custody on a probation hold. Id. at 374, 369 N.W.2d at 383. On August 4, his probation was revoked. On September 10, he was sentenced on the drug charges underlying his probation and imprisoned. He returned to court on March 23, 1983, on the burglary charge, pleaded guilty and was sentenced to a concurrent three-year prison term. He was given credit on the burglary sentence for seventy-eight days — from June 26 (the date of his burglary arrest) to September 10 (the date of sentencing on the drug charge). He claimed he was entitled to an additional 192 days — from the date of his sentencing on the drug charge to the date of his burglary sentence: in essence, for the time he spent in prison on the drug charge while still awaiting sentence on the burglary charge. Id. at 375, 369 N.W.2d at 383.
As indicated, the supreme court, adopting our reasoning in State v. Gavigan, 122 Wis. 2d 389, 362 N.W.2d 162 (Ct. App. 1984), denied the request.
As we held above, of course — and as in Gavigan and Beets — when Harr was adjudged NGI and committed to Mendota, his custody from that point on was not due, in whole or in part, to his inability to meet the bail on the firearms charge; it was occasioned solely by the process in the other case.