There must be a dozen ways to do this. Which is easiest and most efficient depends upon your situation.
Explain your issue in more detail, including how often this will need to be done, and give us the layout of your table.
If it's not practically useful, then it's practically useless.
A stored procedure is a group of Transact-SQL statements compiled into a single execution plan.
Stored procedures assist in achieving a consistent implementation of logic across applications. The SQL statements and logic needed to perform a commonly performed task can be designed, coded, and tested once in a stored procedure. Each application needing to perform that task can then simply execute the stored procedure. Coding business logic into a single stored procedure also offers a single point of control for ensuring that business rules are correctly enforced.
This is just a tip of an iceberg..For more info refer Books online.