alt text http://agricam.net/test.gif
I need to add a row dynamically in SQL after the Marketer number changes with the header ‘Marketer Total’ that should add only the ‘Total’ column. For example, after the last row of Marketer 22 row, there should be ‘Marketer Total’ and then under the Total column should be 1804. The same should occur after the last row of Marketer 500.
See image at http://agricam.net/test.gif
Current Query:
select Marketer, SubMarketer, Grade, Total, Convert(varchar,Date,101)[Date] from SomeTable where Date >= ‘2/25/2009’ and Date < ‘2/26/2009′ and Marketer in (’22’,’500′) group by SubMarketer,Grade,Marketer, Date , total order by Marketer
Thanks.
see Using ROLLUP to aggregate data in SQL
implementation:
attention: this will work fine if MARKETER, SUBMARKETER and DATE columns are NOT NULL. If there will be NULL values of theese fields in table, that will became an issue to filter out useless grouping.