日期:2014-05-18  浏览次数:21201 次

报表问题???
实现下列情况:
出单日期   公司   金额
2007-1-1     A         33
2007-1-1     B         44
                  合计:   77
2007-1-2     C         33
2007-1-2     D         55
                  合计:   88

在.net2005的报表项目中中实现按时间汇总



------解决方案--------------------
--创建建测试环境
create table #t(date datetime,company varchar(20),amount int)

--插入测试数据
insert #t(date,company,amount)
select '2007-1-1 ', 'A ', '33 ' union all
select '2007-1-1 ', 'B ', '44 ' union all
select '2007-1-2 ', 'C ', '33 ' union all
select '2007-1-2 ', 'D ', '55 '

--求解过程
select date,case when grouping(company) = 1 then '合计: ' else company end as company
,sum(amount) from #t
group by date,company with rollup
having grouping(date) = 0

--删除测试环境
drop table #t

/*--测试结果
date company
------------------------------------------------------ -------------------- -----------
2007-01-01 00:00:00.000 A 33
2007-01-01 00:00:00.000 B 44
2007-01-01 00:00:00.000 合计: 77
2007-01-02 00:00:00.000 C 33
2007-01-02 00:00:00.000 D 55
2007-01-02 00:00:00.000 合计: 88

(所影响的行数为 6 行)
*/