QM eigenstate expansion

Why sometime we use the integral to expand the eigenstates and sometime we use the sum to expand? now i am read the modern quantum mechanics J.J.Sakurai text and confusing