David A. Leuchtmann appeals from the Circuit Court of Cole County’s sua sponte dismissal of his petition for declaratory judgment for failing to state a claim for which relief could be granted. Appellant sought a declaration that he was entitled to jail time credit under § 558.031.1 Because we find that Appellant’s petition sufficiently pled a justiciable controversy, we reverse the trial court’s dismissal and remand for further proceedings.
“In reviewing the trial court’s dismissal of a petition for failure to state a claim upon which relief could be granted, this court deems the facts pleaded in the petition to be true.” Roy v. Missouri Dept. of Corrections, 23 S.W.3d 738, 741 (Mo.App. W.D.2000). In his petition, Appellant alleged the following facts.
In August 2000, Appellant was on probation related to a five-year prison sentence. On August 25, 2000, Appellant was arrested upon probable cause to believe he had been operating a motor vehicle while intoxicated. According to the arresting officer, Appellant refused to submit to a chemical breath test after being read the Implied Consent Warnings. Appellant contends that he did not refuse to submit to the chemical test.2
On December 6, 2000, Appellant was taken into custody and placed in the Franklin County Jail after a probation violation report was filed based upon the events of August 25, 2000. In his petition, Appellant contends that he was taken into custody “as a direct and related result of the pending charge” in his driving while intoxicated case. Appellant avers that the reason stated in the probation violation report was his refusal to submit to the chemical breath test following his arrest for driving while intoxicated. On January 5, 2001, Appellant’s probation was officially revoked based upon the probation violation report. On January 30, 2001, Appellant was transferred into the custody of the Missouri Department of Corrections, where he has remained.
On September 11, 2001, Appellant pled guilty to one count of operating a motor vehicle while intoxicated. On September 18, 2001, the trial court sentenced him to a term of four years in the Missouri Department of Corrections to be served concurrently with his prior sentence.
Subsequently, the Department refused to credit the time Appellant spent incarcerated from December 6, 2000, through September 18, 2001, against his sentence for operating a motor vehicle while intoxicated. On January 31, 2002, Appellant filed his petition for declaratory judgment in the Circuit Court of Cole County requesting a declaration that he was entitled *478to credit for the time he was in custody from December 6, 2000, through September 18, 2001.
On February 27, 2002, prior to the Department entering an appearance or filing any responsive pleadings, the circuit court sua sponte dismissed Appellant’s petition for fading to state a claim for which relief could be granted. Appellant brings two points on appeal from that judgment.
In his first point, Appellant claims that the trial court erred in dismissing his petition for failing to state a claim for which relief could be granted because he sufficiently pled a cause of action for declaratory relief. In deciding whether to dismiss a petition for declaratory judgment for failure to state a claim upon which relief may be granted, the trial court is not to address the merits of the claim. Wright v. Department of Corrections, 48 S.W.3d 662, 666 (Mo.App. W.D.2001). “ ‘The question is not whether the petition’s stated theory demonstrates an entitlement to the declaratory relief sought, but rather it is whether under the averments of the petition plaintiff is entitled to a declaration of rights at all.’ ” Id. at 667 (quoting Sandy v. Schriro, 39 S.W.3d 853, 856 (Mo.App. W.D.2001) (quoting City of St. Peters v. Concrete Holding Co., 896 S.W.2d 501, 504 (Mo.App. E.D.1995))). “ ‘If the facts demonstrate any justiciable controversy, the trial court should declare the rights of the parties.’ ” Roy, 23 S.W.3d at 742-43 (quoting Jones v. Carnahan, 965 S.W.2d 209, 214 (Mo.App. W.D.1998)).
In reviewing the trial court’s dismissal of a petition for failure to state a claim upon which relief could be granted, we must deem all well pleaded facts to be true and construe the averments liberally, drawing all reasonable and fair inferences from the facts pleaded. Id. “ ‘If under the facts pleaded a plaintiff is entitled to a declaration of rights at all, the petition is sufficient for that purpose even though it advances a mistaken contention of law.’ ” Wright, 48 S.W.3d at 666 (quoting Sandy, 39 S.W.3d at 856) (internal quotation omitted).
Appellant argues that he sufficiently pled a cause of action for declaratory relief requesting a declaration that he was entitled to credit for the time served based upon § 558.031 and Goings v. Missouri Department of Corrections, 6 S.W.3d 906 (Mo. banc 1999). Since we are merely reviewing the sufficiency of Appellant’s pleadings, the limited question before this court is whether Appellant adequately alleged a claim upon which relief could be granted under § 558.031. See Kay v. Schriro, 54 S.W.3d 700, 702 (Mo.App. W.D.2001).
Section 558.031.1 provides:
A sentence of imprisonment shall commence when a person convicted of a crime in this state is received into the custody of the department of corrections or other place of confinement where the offender is sentenced. Such person shall receive credit toward the service of a sentence of imprisonment for all time in prison, jail or custody after the offense occurred and before the commencement of sentence, when the time in custody was related to that offense ....
In Goings v. Missouri Department of Corrections, 6 S.W.3d 906 (Mo. banc 1999), the Supreme Court interpreted § 558.031, RSMo, to require that a man, who had committed a new crime while on parole status and been returned to prison for the parole violation “related to” his arrest for the new crime, be given jail time credit against the new crime for the time spent in custody from the date of the parole revocation until the time of sentencing on the new crime. Id. at 907. In Goings, Mr. *479Goings was on parole from prison after serving a portion of a five year sentence when he was arrested on felony stealing charges. Id. at 906-07. Mr. Goings was returned to the custody of the Department of Corrections after it was determined that he had violated the conditions of his parole. Id. at 907. Subsequently, Mr. Goings was sentenced to a five-year term of imprisonment on the stealing charge to be served concurrently with his first sentence. Id. Mr. Goings filed a petition for declaratory judgement in the Circuit Court of Cole County after the department refused to give him credit against the sentence for stealing under § 558.031 for the time he was incarcerated from the time his parole was revoked until he was sentenced on the stealing charge. Id. The circuit court denied Mr. Going’s claim. Id. On appeal, the Missouri Supreme Court held that Mr. Goings was entitled to the credit against his second sentence under § 558.031 because the revocation of his parole and subsequent incarceration were “related to” the stealing offense. Id. at 908.
The allegations in Appellant’s petition in the case at bar are factually similar to Goings. Appellant’s pleadings aver that he was on probation at the time of his arrest for driving while intoxicated and that his probation was revoked and he was taken back into custody as a “direct and related result” of that arrest and the arresting officer’s report that he refused to submit to the requested chemical breath test following his arrest. Appellant contends that he is entitled to a jail time credit against his driving while intoxicated sentence under § 558.031 for the time he was in custody from the date of the revocation of his probation until his sentencing on the driving while intoxicated charge because that period of incarceration was “related to” his drunk driving offense. Appellant asserts that the department has refused to grant him jail time credit against his second sentence for that period of incarceration and asks for a declaration that he be entitled to such a credit.
In response to Appellant’s argument that dismissal for failure to state a claim was inappropriate, the Department contends that Appellant failed to state a claim because he “failed to aver that the custodial authority had endorsed the time for which he sought jail time credit as required under § 558.031.2.” Section 558.031.2 provides, “The officer required by law to deliver a person convicted of a crime in this state to the department of corrections shall endorse upon the papers required by section 217.305, RSMo, both the dates the offender was in custody and the period of time to be credited toward the service of the sentence of imprisonment, except as endorsed by such officer.” The Department argues that Appellant’s petition is fatally defective for failing to aver that the sheriff had filled out the proper endorsement papers for the time he was in jail from December 6, 2000, until January 30, 2001, and that those papers had been received by the Department.
The Department fails to explain how or why any failure of the proper legal officer to file the paperwork legislatively mandated by § 558.031.2 would effect the calculation of any jail time credit Appellant was entitled to under § 558.031.1. Section 558.031.1 makes no reference to endorsement paperwork in setting forth when a convict should receive credit toward the service of a sentence of imprisonment. Appellant did not need to aver that the proper paperwork had been filed by the sheriff in accordance with § 558.031.2 in order to plead a cause of action requesting a declaration of his rights under § 558.031.1. The Department’s argument is wholly without merit.
*480The Department’s remaining argument relates to the merits of Appellant’s claim rather than the sufficiency of the petition in stating a claim.3 However, the trial court’s decision to dismiss a petition for declaratory relief for failing to state a claim cannot rest on the merits of the claim. Wright, 48 S.W.3d at 666.
Viewing the petition in accordance with our standard of review, “it cannot be said with certainty that [Appellant] is not entitled to a declaration of rights, duties and obligations under the law as applied to the particular factual circumstances averred in his petition.” Id. Appellant’s petition clearly avers a justiciable issue in controversy between himself and the Department that is presently appropriate for judicial determination.4 While further factual development of the case may demonstrate that Appellant’s return to custody was not “related to” his operating a motor vehicle while intoxicated offense or that § 558.031 does not apply for some other reason, he has “sufficiently pleaded a relationship between his re-incarceration and the new offense and his rights under the statute to survive a motion to dismiss for failure to state a claim.” Kay, 54 S.W.3d at 702.
In his second point, Appellant contends that the trial court erred in failing to enter judgment in his favor on the merits of his claim. Obviously, at the time the trial court dismissed Appellant’s petition, the case was not in a proper posture where judgment could have been entered. The Department had not even filed an answer to Appellant’s petition, and no motion for summary judgment was before the court. The trial court cannot be deemed to have erred in failing to have ruled on the merits of the case. Point denied.
For the foregoing reasons, the trial court’s judgment is reversed and the cause remanded with directions “ ‘to permit the parties to properly submit the issue for adjudication in a manner consistent with this opinion, either by a motion for summary judgment or by [other appropriate means].’ ” Wright, 48 S.W.3d at 667 (quoting Sandy, 39 S.W.3d at 856 (quoting City of St. Peters, 896 S.W.2d at 504)).
All concur.
. All statutory references are to RSMo 2000 unless otherwise noted.
. Appellant states that he asked to contact an attorney and that the officer did not afford him twenty minutes to do so before determining that his failure to submit to the test constituted a refusal.
. The Department argues that Appellant is not entitled to any jail time credit under § 558.031.1 because his probation was revoked for refusing to comply with the arresting officer’s request that he take a chemical test of his breath and was therefore not "related to" his offense of operating a motor vehicle while intoxicated. This is one of the issues in controversy between Appellant and the Department.
. See Wright v. Department of Corrections, 48 S.W.3d 662, 666 (Mo.App. W.D.2001) (reversing the Circuit Court of Cole County's sua sponte dismissal of an inmate’s declaratory judgment action for failing to state a claim where the prisoner requested a declaration related to whether the Department was properly interpreting the applicable statutes and calculating his parole eligibility date); Kay v. Schriro, 54 S.W.3d 700 (Mo.App. W.D.2001) (reversing the Circuit Court of Cole County’s sua sponte dismissal of an inmate’s petition for declaratory relief for failing to state a claim where the prisoner sought a declaration related to whether he was entitled to a jail time credit under § 558.031); Roy v. Missouri Department of Corrections, 23 S.W.3d 738 (Mo.App. W.D.2000) (reversing the Circuit Court of Cole County’s dismissal of an inmate’s petition for declaratory judgment for failing to state a claim where the inmate sought a declaration that he was entitled to a jail time credit under § 558.031).