Be sure to read my article on SQLServerCentral on building aggregate queries: http://www.sqlservercentral.com/columnists/kKellenberger/aggregatequeries.asp