The algebraic treatment of the eigenvalue equations for quantum systems, based on the introduction of the spectrum-generating algebra SO 2.1, in the sense of a previous work, is generalized by allowing energy-dependent realizations of the algebra. A basic differential equation (3.10) is derived, which expresses in a concise way the conditions that the Hamiltonian of the system must satisfy in order that an algebraic treatment, within our framework, be possible. The formalism is such that it allows a straightforward and unified rederivation of all results previously obtained by algebraic methods both for the nonrelativistic and relativistic cases, and also, to some extent, a discussion of the Dirac equation with an electrostatic potential, which has not been solved algebraically up to now. Moreover, the obtained equation (3.10) yields in a natural way the link between the algebraic treatment of quantum systems based on the SO 2.1 algebra and the theory of differential equations. It is shown that the conditions that the system must satisfy in order to have SO 2.1 as spectrum-generating algebra in our sense lead to the same condition as the one obtained by imposing that the Schrödinger equation can be reduced, by means of a functional transformation, to the confluent hypergeometric equation. This result is particularly interesting since all quantum-mechanical systems that have been solved algebraically up to now possess SO 2.1 as spectrum-generating algebra.