Douglas R. Stinson, Jr. (Plaintiff) was convicted of possession of ephedrine with intent to manufacture, § 195.246.1 He was sentenced to five years’ imprisonment. Imposition of sentence was suspended, and Plaintiff was released on probation. Later, Plaintiffs probation was revoked, and the trial court ordered that the five-year sentence be executed. On February 28, 2000, the trial court ordered Plaintiffs release from the custody of the Department of Corrections (DOC) pursuant to § 559.115.2 and again placed Plaintiff on probation. In July 2001 Plaintiffs probation was revoked and again he was delivered to the DOC.
On December 13, 2001, Plaintiff filed a “Petition for Declaratory Judgment” against The Honorable Stephen Sharp, the sentencing judge. The petition alleges, inter alia, that Plaintiff is entitled to credit toward his sentence for the time he spent on “parole” after his release from the DOC in February 2000 until his redelivery to the DOC in July 2001. For this time period, Plaintiff alleges he was on “parole” as defined in § 217.650(4), and pursuant to § 217.730.1, he is entitled to a credit for the time served on parole.
The trial court dismissed Plaintiffs petition after finding that it failed to state a claim.2 Plaintiff, acting pro se, appeals the dismissal of his petition.
*854Plaintiffs first point contends the trial court erred in concluding that his petition failed to state a claim because § 217.730.1 entitles him to a credit for time served on “parole.” We disagree.
In determining whether Plaintiffs petition for declaratory judgment was sufficient to survive a motion to dismiss, we deem the facts pleaded to be true, construe the averments liberally, and draw all reasonable and fair inferences from the facts pleaded. Bailey v. Bd. of Prob. & Parole, 36 S.W.3d 13, 15 (Mo.App.2000). If the allegations in the petition invoke principles of substantive law which, if proved, entitle the pleader to a declaration of rights or status, the pleading is sufficient and must not be dismissed. Id.
We agree with Plaintiff that Roy v. Missouri Dep’t of Corr., 23 S.W.3d 738, 744 (Mo.App.2000), holds that a prisoner may bring a declaratory judgment action regarding entitlement to a credit for jail time under § 558.031. Other cases so hold. See Goings v. Missouri Dep’t of Corr., 6 S.W.3d 906 (Mo. banc 1999), and Bates v. Missouri Dep’t of Corr., 986 S.W.2d 486, 489 (Mo.App.1999). However, in these cases, the declaratory judgment action was brought against the DOC, not the sentencing judge as here.
In this case, the DOC is not a party. Plaintiff is in the custody of the DOC, an entity that can sue and be sued. § 217.020(2). As demonstrated in Roy, plaintiff “could properly request a determination of his entitlement to credit on his sentences in a declaratory judgment petition.” 23 S.W.3d at 744. As stated, this rule is applied only where the prisoner’s custodian is a party.
A trial court has no authority to grant relief against a nonparty. American Family Mut. Ins. Co. v. Scott, 988 S.W.2d 45, 47 (Mo.App.1998). In this case, Plaintiff is asking the sentencing judge to declare that the DOC must give him a credit towards his sentence. Plaintiffs quarrel is clearly with the DOC, yet, the DOC has had no opportunity to contest whether Plaintiffs request for credit on his sentence is valid. Certainly, any judgment granting Plaintiffs requested relief would have no binding effect on the DOC. Thus, Plaintiff cannot obtain declaratory judgment relief, as requested, against Judge Sharp.
A declaratory judgment is only appropriate where a plaintiff can obtain relief against the defendant. King Louie Bowling Corp. v. Missouri Ins. Guar. Ass’n, 735 S.W.2d 35, 38 (Mo.App.1987). The “function of declaratory judgment is to dispel uncertainty as to legal rights.” Id.
Plaintiffs legal right to relief does not he against the sentencing judge. His right to relief, if any, must be asserted against the entity restraining his freedom until Plaintiff serves his proper sentence. That entity is the DOC. Therefore, Plaintiff does not state a claim for relief against Judge Sharp. Point denied.
Plaintiff also alleges the trial court erred in dismissing his petition because the Prisoner Litigation Reform Act is unconstitutional. Our primary concern is whether the trial court’s decision is correct, “not the route taken by the trial court to reach that result.” Business Men’s Assurance Co. of America v. Graham, 984 S.W.2d 501, 506 (Mo. banc 1999). Therefore, the judgment will be affirmed if cognizable under any theory even if the reasons advanced by the trial court are wrong or insufficient. Id. We have determined the trial court properly dismissed Plain*855tiffs petition for failure to state a claim. Thus, we need not decide Point II.
The judgment is affirmed.
GARRISON, J., and BARNEY J., concur.. Statutory references are to RSMo 2000 unless otherwise indicated.
. The trial court also determined that Plaintiff failed to comply with the Prisoner Litigation *854Reform Act, §§ 506.360 to 506.390, and that Plaintiffs claim was frivolous.