回 帖 发 新 帖 刷新版面

主题:存储过程统计报表...求助

表A
id    ODate      UseNumber
1   2005-01-20    10
2   2005-01-25    10
3   2005-03-10    10
4   2005-03-11    10
5   2007-11-20    10

现在要根据查询的时间段列出相应的统计数据
比如我要查询2005-01到2007-11月的数据
就列出以下结构数据
日期        使用量
2005-01       20
2005-03       20
2007-11       10
使用量=当月(UseNumber)的合计
  假设我传入此存储过程的时间变量为@stime @etime

回复列表 (共2个回复)

沙发

create proc count_print_num
 @stime datetime=null,
 @etime datetime=null
as
 select convert(varchar(7),ODate,120) as '日期',sum(UseNumber) as '使用量' from 表A
 where (@stime is null or @etime is null or (ODate>=@stime and ODate<=@etime))  
 group by convert(varchar(7),ODate,120)
GO

板凳


用的FineReport报表做的?

我来回复

您尚未登录,请登录后再回复。点此登录或注册