,欢迎访问网页设计爱好者web开发。
crystal reports 和sql-server共同进行报表的开发
1:crystal reports功能自述
crystal reports 用于处理数据库,帮助用户分析和解释重要信息。使用 crystal reports 可以方便地创建简单报表,同时它也提供了创建复杂或专用的报表所需的整套工具。
创建所能想象的任何报表
crystal reports 几乎可以从任何数据源生成您需要的报表。内置报表专家在您生成报表和完成一般的报表任务过程中,会一步一步地指导您进行操作。报表专家通过公式、交叉表、子报表和设置条件格式帮助表现数据的实际意义,揭示可能被隐藏掉的重要关系。如果文字和数字确实不够充分,则用地理地图和图形进行形象的信息交流。
将报表扩展到 web
crystal reports 的灵活性并未停留在创建报表这一功能上 ?您可以用各种各样的格式发布报表,包括用 microsoft 的 word 和excel 发布、通过电子邮件甚至 web 发布。高级的 web 报表功能允许工作组中的其他成员在他们自己的 web 浏览器中查看或更新共享报表。
将报表并入应用程序
通过将 crystal reports 的报表处理功能整合到自己的数据库应用程序中,应用程序和 web 开发人员可以节省开发时间并满足用户的需求。crystal reports 支持大多数流行的开发语言,可以方便地在任何应用程序中添加报表。
不论您是 it 行业的站点管理员,还是营销推广经理,也无论您是金融业的数据库管理员还是 ceo,crystal reports 都堪称是一个功能强大的工具,它可以帮助每一个人分析、解释重要信息。
2:crystal reports和sql-server结合
crystal虽然提供了强大的报表功能,但是对于复杂的逻辑运算,却是很难实现。但是,crystal中可以像添加表一样添加存储过程,这就给我们的复杂运算提供了简便的处理方法。
3:例子
这是我们给国航公司it服务项目做的报表的sql-server存储过程部分。(欢迎大家共同讨论)
a:每个员工的处理故障完成数、总数
fgw_proc1.txt
--fgw_proc1 处理故障完成数、总数
create procedure [ahd].[fgw_proc1](@开始时间 datetime , @结束时间 datetime)
as
declare @begin int , @end int /*转时间*/
exec fgw_util1 @开始时间, @begin output
exec fgw_util1 @结束时间, @end output
declare @userid int, @handled float, @total float
create table #temp_proc1
(
userid int,
handled float,
total float
)
declare cur_ctct cursor for select id from ahd.ahd.ctct --取所有的用户id
open cur_ctct
fetch cur_ctct into @userid
while @@fetch_status = 0
begin
--get @handle through exec fgw_proc2
exec fgw_proc1_1 @userid , @begin , @end , @handled output , @total output /*call下个存储过程,得到某个用户的解决数、接触故障数*/
insert into #temp_proc1 values (@userid , @handled , @total) /*将用户信息插入临时表*/
fetch next from cur_ctct into @userid /*记录下移*/
end
close cur_ctct
deallocate cur_ctct
select * from #temp_proc1 /*生成结束集*/
drop table #temp_proc1 /*释放*/
go
fgw_proc1_1.txt
--fgw_proc1_1
create procedure [ahd].[fgw_proc1_1](@userid int , @begin int , @end int , @handled float output , @total float output)
as
set @handled = 0
set @total = 0
declare @cr_id int, @zh_id int, @status char(12), @to_status char(12), @cnt int, @open_date int
--handled /*计算此人的处理完成故障数*/
declare cur11_1 cursor for select ahd.call_req.id as cr_id, ahd.ztr_his.id as zh_id, ahd.call_req.status, ahd.ztr_his.to_status, ahd.ztr_his.to_cnt as cnt, ahd.call_req.open_date from ahd.call_req left outer join ahd.ztr_his on ahd.call_req.persid = ahd.ztr_his.call_req_id where ahd.call_req.type='i' and (ahd.call_req.status in ('cl', 'ttpc')) and (ahd.ztr_his.to_status in ('l1wip', 'l2wip', 'icp', 'srbyl1', 'srbyl2', 'nccbyl1', 'nccbyl2', 'crbyl1', 'crbyl2')) and ahd.call_req.open_date>@begin and ahd.call_req.open_date<@end and ahd.ztr_his.to_cnt = @userid
open cur11_1
fetch cur11_1 into @cr_id, @zh_id, @status, @to_status, @cnt, @open_date /*事件id,历史id,状态,处理人,打开时间取所需要的值*/
while @@fetch_status = 0 /*循环每一个记录*/
begin
declare @count2 int /*每个事件单在历史记录中有多少条*/
declare cur11_2 cursor for select count(*) from ahd.call_req left outer join ahd.ztr_his on ahd.call_req.persid = ahd.ztr_his.call_req_id where ahd.call_req.type='i' and (ahd.call_req.status in ('cl', 'ttpc')) and (ahd.ztr_his.to_status in ('l1wip', 'l2wip', 'icp', 'srbyl1', 'srbyl2', 'nccbyl1', 'nccbyl2', 'crbyl1', 'crbyl2')) and (ahd.call_req.open_date>@begin) and (ahd.call_req.open_date<@end) and (ahd.call_req.id = @cr_id)
open cur11_2
fetch cur11_2 into @count2
close cur11_2
deallocate cur11_2
if @count2 <> 0
set @handled = @handled + 1.0 / @count2 /*此人的处理完成数*/
fetch next from cur11_1 into @cr_id, @zh_id, @status, @to_status, @cnt, @open_date /*循环记录*/
end
close cur11_1
deallocate cur11_1
--total /*计算此人的处理故障数*/
declare cur11_3 cursor for select count(distinct(ahd.call_req.id)) from ahd.call_req left outer join ahd.ztr_his on ahd.call_req.persid = ahd.ztr_his.call_req_id where ahd.call_req.type='i' and (ahd.call_req.open_date>@begin and ahd.call_req.open_date<@end) and (ahd.ztr_his.to_cnt = @userid) /*取此人所有单*/
open cur11_3
fetch cur11_3 into @total /*总故障数*/
close cur11_3
deallocate cur11_3
--select @handled
--declare @handled float,@total float
--exec fgw_proc1_1 400115,1,1111111111,@handled output ,@total output
--print @handled
--print @total
go
b:每个员工的响应达标数、响应总数
fgw_proc2.txt
--fgw_proc2 响应达标数、响应总数
create procedure [ahd].[fgw_proc2](@开始时间 datetime , @结束时间 datetime)
as
declare @begin int , @end int
exec fgw_util1 @开始时间, @begin output
exec fgw_util1 @结束时间, @end output
declare @cr_id int, @zh_id int, @cnt int, @sym char(30), @time_stamp int, @isok int , @userid int , @handled int , @total int
declare @call_req_id char(30)
create table #temp_proc2 /* 响应达标数、响应总数*/
(
userid int,
handled2 int,
total2 int
)
create table #temp_proc2_1 /* 事件单为op的记录*/
(
cr_id int,
zh_id int,
cnt int,
isok int
)
--initialize #temp_proc2_1 /*已经op的单,是否响应达标,返回处理人*/
declare cur2_1 cursor for select zh.call_req_id,zh.id,zh.to_cnt,sd.sym,zh.time_stamp from ahd.ahd.call_req as cr left outer join ahd.ahd.ztr_his as zh on cr.persid=zh.call_req_id left outer join ahd.ahd.srv_desc as sd on cr.support_lev=sd.code where cr.type='i' and cr.open_date>@begin and cr.open_date<@end and (zh.to_status='astol1' or zh.to_status='astol2')
open cur2_1
fetch cur2_1 into @call_req_id, @zh_id, @cnt, @sym, @time_stamp /*事件单id,历史单id,人员,服务级别,op状态的时间*/
while @@fetch_status = 0
begin
exec fgw_proc2_1 @call_req_id , @sym , @time_stamp , @isok output
insert into #temp_proc2_1 values (@cr_id , @zh_id , @cnt , @isok)
fetch next from cur2_1 into @call_req_id, @zh_id, @cnt, @sym, @time_stamp
end
close cur2_1
deallocate cur2_1
--initialize #temp_proc2
declare cur2_2 cursor for select id from ahd.ahd.ctct
open cur2_2
fetch cur2_2 into @userid
while @@fetch_status = 0
begin
--get @total /*所有的已响应的单*/
declare cur2_3 cursor for select count(*) from #temp_proc2_1 where cnt = @userid
open cur2_3
fetch cur2_3 into @total
close cur2_3
deallocate cur2_3
--get @handled /*所有的已响应的单,并达标的单*/
declare cur2_4 cursor for select count(*) from #temp_proc2_1 where cnt = @userid and isok=1
open cur2_4
fetch cur2_4 into @handled
close cur2_4
deallocate cur2_4
insert into #temp_proc2 values (@userid , @handled , @total)
fetch next from cur2_2 into @userid
end
close cur2_2
deallocate cur2_2
drop table #temp_proc2_1
select * from #temp_proc2
drop table #temp_proc2
go
fgw_proc2_1.txt
--fgw_proc2_1
create procedure [ahd].[fgw_proc2_1](@call_req_id char(30) , @level char(30) , @time_stamp int , @isok int output)
as
set nocount on
set @isok = 0
declare cur_zh cursor for select time_stamp from ahd.ahd.ztr_his where call_req_id = @call_req_id and to_status in ('l1wip','l2wip') and time_stamp>@time_stamp
open cur_zh
declare @time_stamp1 int
set @time_stamp1=0
fetch cur_zh into @time_stamp1
if (@time_stamp1 is not null) and (@time_stamp1<>0)
begin
if charindex('一级', @level) is not null and charindex('一级', @level)<>0
begin
if @time_stamp1 - @time_stamp <600
set @isok=1
end
else if charindex('二级', @level) is not null and charindex('二级', @level)<>0
begin
if @time_stamp1 - @time_stamp <1800
set @isok=1
end
else if charindex('三级', @level) is not null and charindex('三级', @level)<>0
begin
if @time_stamp1 - @time_stamp <1800
set @isok=1
end
else if charindex('四级', @level) is not null and charindex('四级', @level)<>0
begin
if @time_stamp1 - @time_stamp <1800
set @isok=1
end
end
close cur_zh
deallocate cur_zh
--select @isok, @time_stamp1
go
c:每个员工的处理时限达标数,总数
fgw_proc3.txt
--fgw_proc3
create procedure fgw_proc3(@开始时间 datetime , @结束时间 datetime)
as
/*时间转换*/
declare @begin int , @end int
exec fgw_util1 @开始时间, @begin output
exec fgw_util1 @结束时间, @end output
declare @cr_id int, @zh_id int, @cnt int, @sym char(30), @time_stamp int, @isok int , @userid int , @handled int , @total int
create table #temp_proc3
(
userid int,
handled2 int,
total2 int
)
declare cur3_2 cursor for select id from ahd.ahd.ctct
open cur3_2
fetch cur3_2 into @userid
while @@fetch_status = 0
begin
--get @handled
declare cur3_4 cursor for select distinct(cr.id) from ahd.ahd.call_req as cr left outer join ahd.ahd.ztr_his as zh on cr.persid=zh.call_req_id where cr.type='i' and cr.open_date>@begin and cr.open_date<@end and zh.to_cnt = @userid and cr.sla_violation=0
open cur3_4
set @handled = @@cursor_rows
close cur3_4
deallocate cur3_4
--get @total
declare cur3_5 cursor for select distinct(cr.id) from ahd.ahd.call_req as cr left outer join ahd.ahd.ztr_his as zh on cr.persid=zh.call_req_id where cr.type='i' and cr.open_date>@begin and cr.open_date<@end and zh.to_cnt = @userid
open cur3_5
set @total = @@cursor_rows
close cur3_5
deallocate cur3_5
insert into #temp_proc3 values (@userid , @handled , @total)
fetch next from cur3_2 into @userid
end
close cur3_2
deallocate cur3_2
select * from #temp_proc3
drop table #temp_proc3
d:将日期格式转换成整型
fgw_util1.txt
--fgw_util1
create procedure [ahd].[fgw_util1] (@time datetime, @seconds int output)
as
set @seconds=datediff(ss,'1970-01-01 00:00:00', @time)
go
例子只是整盘拷贝了代码,欢迎大家共同讨论