• Sounds like you could use Rollup or Cube see this article in BOL.