
174 S.W.3d 689 (2005)
Elmer H. VAN DYKE, Appellant,
v.
LVS BUILDING CORPORATION, Respondent.
No. WD 64833.
Missouri Court of Appeals, Western District.
October 25, 2005.
*690 Jeffrey L. Dull, Clinton, MO, for appellant.
Mark T. Kempton, Sedalia, MO, for respondent.
Before RONALD R. HOLLIGER, P.J., ROBERT G. ULRICH and JOSEPH M. ELLIS, JJ.
ROBERT G. ULRICH, Judge.
Elmer Van Dyke, M.D. appeals the judgment of the Pettis County Circuit Court granting LVS Building Corporation's counterclaim for declaratory judgment, wherein the court determined the value of Mr. Van Dyke's stock in LVS Building Corporation as of the date of his request for redemption was $230.00 per share based on the "stock price" set by the annual meeting of shareholders and not $471 per share as provided by the formula stated in the 1998 shareholder's agreement. Because the allegations in LVS Building Corporation's claim for declaratory relief fail to state a claim upon which relief can be granted, the judgment of the trial court is reversed and the cause is remanded to address Dr. Van Dyke's breach of contract claim.

Facts
Dr. Van Dyke was a founder and shareholder in LVS Building Corporation (LVS).[1] LVS was formed in 1968 with the primary purpose of owning and managing facilities for physicians to house and operate their practices. LVS's shareholders are physicians who benefit from this primary purpose. Throughout Dr. Van Dyke's involvement with LVS, the shareholders, he included, executed three different Buy and Sell Agreements. The last *691 agreement was entered into on January 19, 1988. This agreement contained provisions for the redemption of shares in certain instances. These instances included death, disability, and retirement once a shareholder attained the age of 60. The 1988 agreement contained a formula for calculating an "endorsed value" of the shares. LVS shareholders voted at the annual meetings, however, on an "estate value," "estate price," "stock estate price," or "stock price."
On December 13, 2002, Dr. Van Dyke gave notice to LVS of his intent to have his stock redeemed pursuant to the 1988 agreement. At that time, Dr. Van Dyke was 65 years of age or older and owned 620 shares of stock. Dr. Van Dyke claimed his stock should be valued using the formula contained in the 1988 agreement; using the formula, Dr. Van Dyke's shares were valued at $471.00 per share. LVS informed Dr. Van Dyke that it would redeem his shares, but it used the "stock price" set at the last annual meeting of the shareholders, which was $230.00 per share. Thus, the dispute is the value of Dr. Van Dyke's shares, and the issue is whether the stock value should be determined by the 1998 agreement or by the "stock price" set at the annual meeting of shareholders preceding Dr. Van Dyke's notice to redeem his shares.
Dr. Van Dyke brought suit in Pettis County Circuit Court, claiming that LVS had breached the 1988 Buy and Sell Agreement by failing to redeem his stock for the formula value expressed in the 1988 Agreement. LVS answered that the 1988 Buy and Sell Agreement had been modified by the "stock price" set at the annual shareholder meetings. LVS also counterclaimed for declaratory judgment "declaring the rights of the parties under The Agreement dated January 19, 1998 and declaring the per share value of Elmer H. Van Dyke's stock in said Corporation as of the date of his request for redemption to be $230.00 per share." The trial court entered judgment on LVS's counter claim for declaratory judgment.[2] The judgment declared that the value of Dr. Van Dyke's stock was $230.00 per share, the "stock price" set at the appropriate annual meeting. Dr. Van Dyke timely filed his notice of appeal.

Analysis
Dr. Van Dyke presents four points on appeal, alleging that: (1) the 1988 agreement had not been modified by the annual meetings and that any evidence of modification was improperly admitted; (2) if a modification did occur, it violated the statute of frauds; (3) the circuit court's findings were against the weight of the evidence; and (4) the circuit court erred in failing to award Dr. Van Dyke interest on any sums owed him.
The merits of Dr. Van Dyke's points on appeal need not be addressed because the circuit court abused its discretion in granting the declaratory relief requested by LVS in that LVS's counterclaim fails to state a claim upon which relief can be granted. Dr. Van Dyke does not challenge the sufficiency of LVS's counterclaim; however, "the issue is inherent in every appeal and may be raised sua sponte by the reviewing court." Preferred Physicians Mut. Mgmt. Group, Inc. v. Preferred Physicians Mut. Risk Retention Group, 916 S.W.2d 821, 823 (Mo.App. W.D.1995)(citing Adkisson v. Dir. of Revenue, 891 S.W.2d 131, 132 (Mo. banc 1995); *692 Grippe v. Momtazee, 696 S.W.2d 797, 798 (Mo. banc 1985)).
Under section 527.010,[3] trial courts have the "power to declare rights, status, and other legal relations whether or not further relief is or could be claimed." The trial court is afforded wide discretion in using this power. Small v. Harrah's N. Kansas City Corp., 24 S.W.3d 60, 63 (Mo.App. W.D.2000). An action pursuant to this section "is sui generis, neither legal nor equitable, but its historical affinity is equitable and such actions are governed by equitable principles." Preferred Physicians, 916 S.W.2d at 823. Section 527.120 states that declaratory relief is remedial. Because of this, Missouri courts have long held that the declaratory relief power does not abolish or provide an additional existing remedy but instead addresses a deficiency or bridges a superfluity in the law. Cronin v. State Farm Fire & Cas. Co., 958 S.W.2d 583, 587 (Mo.App. W.D.1997). The purpose of a declaratory judgment is to give parties "relief from uncertainty and insecurity" and to reduce multiple lawsuits. Preferred Physicians, 916 S.W.2d at 823-24.
The declaratory judgment power "is not to be invoked where an adequate remedy already exists." Preferred Physicians, 916 S.W.2d at 824; see also Cronin, 958 S.W.2d at 587-88 (stating that, except in unusual circumstances plainly appearing, a declaratory judgment action cannot be maintained if an adequate remedy exists, regardless of whether the adequate remedy is legal or equitable). "For the purpose of this rule, an adequate remedy exists if the plaintiff could assert the issues sought to be declared as a defense in an action brought by the defendant." Preferred Physicians, 916 S.W.2d at 824. The Missouri Supreme Court has recognized a distinction between alternative remedies which are pending or imminent and those of a more uncertain nature. Id. (citing State v. Terte, 351 Mo. 1089, 176 S.W.2d 25, 30 (1943)). If an action is about to begin or has begun, "it serves no sensible end to permit his adversary to appear as an equitable actor and start the proceedings for an autonomous declaration that he has a good defense to his opponent's pending or imminent action." Id. (quoting Terte, 176 S.W.2d at 30). If no ongoing or imminent suit exists, then a declaratory judgment action serves a useful purpose in resolving the conflict between the parties. Id. (citing Terte, 176 S.W.2d at 30); see also Northgate Apartments, L.P. v. City of N. Kansas City, 45 S.W.3d 475, 481 (Mo.App. W.D.2001)(noting that declaratory relief is more appropriate if there is not an action pending through which the parties could seek the relief sought from the declaratory judgment). "The rule barring the use of declaratory relief when an adequate remedy exists is especially applicable where the issues sought to be declared have been asserted as a defense in the same litigation." Preferred Physicians, 916 S.W.2d at 824. In O'Meara v. New York Life Insurance Co., 237 Mo.App. 409, 169 S.W.2d 116, 122 (1943), this court held that a declaratory judgment counterclaim "has no place" in a case where identical facts have been put forth as a defense to the plaintiff's cause of action. Declaratory relief cannot become a "substitute for all existing remedies and should be used with caution." Preferred Physicians, 916 S.W.2d at 824 (citing O'Meara, 169 S.W.2d at 122).
In Preferred Physicians Mutual Management Group, Inc. v. Preferred Physicians Mutual Risk Retention Group, 916 S.W.2d 821, 824 (Mo.App. W.D.1995), this court reasserted the O'Meara holding and *693 held that declaratory relief was not proper in a breach of contract suit where defendant's counterclaim requesting declaratory relief was identical to the defendant's raised affirmative defense. This court noted that defendant had an adequate remedy in the pending breach of contract suit and reiterated that "it `serves no sensible end' to allow a defendant to seek a declaration by the trial court that he has a meritorious defense to the pending action." Id. (quoting Terte, 176 S.W.2d at 30).
A trial court has "considerable discretion" in determining whether to grant declaratory relief. Id. This court, in Millers Mutual Insurance Ass'n v. Babbitt, 790 S.W.2d 944, 945-47 (Mo.App. W.D.1990), upheld a trial court's declaratory judgment that a victim of a car accident was not entitled to benefits under an insurance policy even though the victim could have brought a suit for recovery under the policy. This court stated that it was "no ground for reversible error that the trial court exercised its discretion to entertain the declaratory judgment action." Id. at 947. While Millers correctly declares that a trial court may exercise its discretion to grant declaratory relief, the exercise of discretion is still subject to appellate review. Preferred Physicians, 916 S.W.2d at 824; see also Cronin, 958 S.W.2d at 588-89. The trial court's exercise of discretion in granting declaratory relief "must be sound, based on good reason, and calculated to serve the purposes for which the legislation was enacted, particularly to provide relief from uncertainty and insecurity." Preferred Physicians, 916 S.W.2d at 824-25; see also Cronin, 958 S.W.2d at 588-89.
Whether a trial court has abused its discretion is determined on a case-by-case basis. Preferred Physicians, 916 S.W.2d at 825. The Missouri Supreme Court has provided factors to consider when determining whether to proceed with a declaratory judgment action. Terte, 176 S.W.2d at 30; see also Preferred Physicians, 916 S.W.2d at 825 (stating that, while Terte addressed a trial court's staying of declaratory relief, it also applies to a trial court's granting of declaratory relief). The factors to consider when determining whether to exercise discretion to grant declaratory relief include "public policy and interest, efficiency, convenience, economy, the good or bad faith of the party bringing the declaratory judgment action," and whether the trial court's grant of declaratory relief will serve the purposes for which the declaratory judgment legislation was enacted. Preferred Physicians, 916 S.W.2d at 825 (citing Terte, 176 S.W.2d at 28, 30).
As elaborated, supra, "it is well settled that a declaratory judgment action will not lie where the declaration is being sought to defend against an action brought against the party seeking declaratory relief." Brock v. Blackwood, 143 S.W.3d 47, 70 n. 6 (Mo.App. W.D.2004). This is because an adequate remedy exists in the action against which the party seeking declaratory relief is defending. Armstrong Bus. Servs., Inc. v. H & R Block, 96 S.W.3d 867, 871 n. 1 (Mo.App. W.D.2002). "This rule is especially applicable where the issues sought to be declared have been asserted as a defense in the same litigation." Id. n.1; see also Parshall v. Buetzer, 121 S.W.3d 548, 551-52 (Mo.App. W.D.2003). That is precisely the situation in this case. Dr. Van Dyke brought suit for breach of the Buy and Sell Agreement. LVS answered the petition, denying or admitting Dr. Van Dyke's allegations. In the same document, LVS also asserted a counterclaim for declaratory relief. This counterclaim merely re-asserted the allegations and denials contained in the Dr. Van Dyke's petition and LVS's answer. LVS's counterclaim *694 raised no new issues and presented no new allegations.
Both parties agreed that the cause would be taken up only on LVS's counterclaim. Dr. Van Dyke's petition was never withdrawn or dismissed, however. Because of this agreement, trial was had on the declaratory relief counterclaim and the circuit court entered judgment only on the declaratory relief counterclaim. Dr. Van Dyke's breach of contract action is still pending. In fact, when Dr. Van Dyke filed his appeal, this court expressed concern that a final, appealable judgment did not exist because Dr. Van Dyke's breach of contract claim was never resolved. The court solicited appellant suggestions as to why the appeal should not be dismissed. Appellant's suggestions included the following statements:
3.... However, since the Counterclaim was equitable in nature and involved the same issues as the Petition for Breach of Contract, the Court set the Counterclaim for a hearing reasoning that any determination under the Counterclaim would in essence resolve the issue under the Petition for Breach of Contract also.
4. The issues on the Petition for Breach of Contract and Declaratory Judgment are identical....
....
6. The Trial Court's decision rendered the Petition for Breach of Contract moot.... All issues, claims, and liabilities between the parties have been adjudicated under the Declaratory Judgment action.
This confirms the conclusion that the issues for which LVS sought declaration in its counterclaim were asserted as a defense in the same litigation, namely Dr. Van Dyke's breach of contract action.
Dr. Van Dyke and LVS's agreement that their dispute would be taken up on LVS's counterclaim for declaratory judgment is of no consequence. LVS's declaratory counterclaim failed to state a claim upon which relief can be granted. The failure to state a claim is related to subject matter jurisdiction. Adkisson, 891 S.W.2d at 132. Subject matter jurisdiction cannot be waived or conferred by agreement of the parties. Noakes v. Noakes, 168 S.W.3d 589, 596 (Mo.App. W.D.2005).
As for Dr. Van Dyke's suggestion that his breach of contract action was rendered moot by the declaratory judgment, this court notes that, as the declaratory judgment counterclaim failed to state a claim, it was a nullity. Brock, 143 S.W.3d at 70 n. 6. Thus, it does not exist and cannot render anything moot.

Conclusion
Under the circumstances of this case, the circuit court erred by ruling on LVS's counterclaim for declaratory relief. "When a declaratory judgment claim improperly invokes § 527.010 because an adequate remedy already exists, that declaratory judgment claim fails to state a cause of action." Preferred Physicians, 916 S.W.2d at 825 (citing Harris v. State Bank & Trust Co. of Wellston, 484 S.W.2d 177, 178-79 (Mo.1972)). The counterclaim "is a nullity and not subject to being ruled on" by the circuit court. Brock, 143 S.W.3d at 70 n. 6. Because LVS's counterclaim failed to state a claim upon which relief can be granted, this court need not address Dr. Van Dyke's four points on appeal. Preferred Physicians, 916 S.W.2d at 825. The circuit court's judgment granting LVS's counterclaim is reversed and the cause is remanded to address Dr. Van Dyke's breach of contract claim.
All concur.
NOTES
[1]  As this appeal is resolved on a jurisdictional basis, the factual statement is abbreviated.
[2]  As will be discussed more fully, infra, the circuit court never held a trial or rendered judgment on Dr. Van Dyke's breach of contract claim; trial was held and judgment was rendered for the declaratory judgment counterclaim only.
[3]  All statutory references are to RSMo 2000 unless otherwise noted.
