分享
 
 
 

存储过程---实践

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

1,fgw_proc1:

CREATE PROCEDURE fgw_proc1(@begin int , @end int)

AS

SET NOCOUNT ON

DECLARE @userid int, @handled float, @total float

CREATE TABLE #temp_proc1

(

userid int,

handled float,

total float

)

--get @total

DECLARE cur_cr CURSOR FOR SELECT count(*) FROM AHD.AHD.call_req where open_date>@begin and open_date<@end

OPEN cur_cr

FETCH cur_cr INTO @total

CLOSE cur_cr

DEALLOCATE cur_cr

DECLARE cur_ctct CURSOR FOR SELECT id FROM AHD.AHD.ctct

OPEN cur_ctct

FETCH cur_ctct INTO @userid

WHILE @@FETCH_STATUS = 0

BEGIN

--get @handle through exec fgw_proc2

EXEC fgw_proc2 @userid , @begin , @end , @handled output

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

drop procedure fgw_proc1

exec fgw_proc1 1,1

2,fgw_proc2

CREATE PROCEDURE fgw_proc2(@userid int , @begin int , @end int , @handled float OUTPUT)

AS

SET NOCOUNT ON

SET @handled = 0

DECLARE @cr_id int, @zh_id int, @status char(20), @to_status char(20), @cnt int, @open_date int

DECLARE cur_crzh CURSOR FOR SELECT * FROM AHD.dbo.FGW_CR_ZH where cnt = @userid

OPEN cur_crzh

FETCH cur_crzh INTO @cr_id, @zh_id, @status, @to_status, @cnt, @open_date

WHILE @@FETCH_STATUS = 0

BEGIN

DECLARE @count2 int

DECLARE cur_crzh2 CURSOR FOR SELECT count(*) FROM AHD.dbo.FGW_CR_ZH where cr_id = @cr_id and open_date>@begin and open_date<@end

OPEN cur_crzh2

FETCH cur_crzh2 INTO @count2

CLOSE cur_crzh2

DEALLOCATE cur_crzh2

IF @count2 != 0

SET @handled = @handled + 1 / @count2

FETCH NEXT FROM cur_crzh INTO @cr_id, @zh_id, @status, @to_status, @cnt, @open_date

END

CLOSE cur_crzh

DEALLOCATE cur_crzh

--SELECT @handled

drop procedure fgw_proc2

exec fgw_proc2 1,1,1

3,fgw_proc3

CREATE PROCEDURE fgw_proc3(@begin int , @end int)

AS

SET NOCOUNT ON

DECLARE @cr_id int, @zh_id int, @cnt int, @sym char(30), @time_stamp int, @isOK int

CREATE TABLE #temp_proc3

(

cr_id int,

zh_id int,

cnt int,

isOK int

)

DECLARE cur_crzhsd CURSOR FOR SELECT cr.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='OP'

OPEN cur_crzhsd

FETCH cur_crzhsd INTO @cr_id, @zh_id, @cnt, @sym, @time_stamp

WHILE @@FETCH_STATUS = 0

BEGIN

--get @handle through exec fgw_proc2

EXEC fgw_proc4 @zh_id , @sym , @time_stamp , @cnt output , @isOK output

INSERT INTO #temp_proc3 VALUES (@cr_id , @zh_id , @cnt , @isOK)

FETCH NEXT FROM cur_crzhsd INTO @cr_id, @zh_id, @cnt, @sym, @time_stamp

END

CLOSE cur_crzhsd

DEALLOCATE cur_crzhsd

SELECT * FROM #temp_proc3

DROP TABLE #temp_proc3

drop procedure fgw_proc3

EXEC fgw_proc3 1, 1111111111

4,fgw_proc4

CREATE PROCEDURE fgw_proc4(@zh_id int , @level char(30) , @time_stamp int , @cnt int OUTPUT , @isOK int OUTPUT)

AS

SET NOCOUNT ON

SET @isOK = 0

DECLARE cur_zh CURSOR FOR SELECT to_cnt,time_stamp FROM AHD.AHD.ztr_his WHERE id = @zh_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 @cnt, @time_stamp1

IF @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

drop procedure fgw_proc4

exec fgw_proc4 1,'1',1,1,1

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有