|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
用一个库#bak_database存放这些历史数据。存储历程
1,fgw_proc1:
CREATEPROCEDUREfgw_proc1(@beginint,@endint)
AS
SETNOCOUNTON
DECLARE@useridint,@handledfloat,@totalfloat
CREATETABLE#temp_proc1
(
useridint,
handledfloat,
totalfloat
)
--get@total
DECLAREcur_crCURSORFORSELECTcount(*)FROMAHD.AHD.call_reqwhereopen_date>@beginandopen_date<@end
OPENcur_cr
FETCHcur_crINTO@total
CLOSEcur_cr
DEALLOCATEcur_cr
DECLAREcur_ctctCURSORFORSELECTidFROMAHD.AHD.ctct
OPENcur_ctct
FETCHcur_ctctINTO@userid
WHILE@@FETCH_STATUS=0
BEGIN
--get@handlethroughexecfgw_proc2
EXECfgw_proc2@userid,@begin,@end,@handledoutput
INSERTINTO#temp_proc1VALUES(@userid,@handled,@total)
FETCHNEXTFROMcur_ctctINTO@userid
END
CLOSEcur_ctct
DEALLOCATEcur_ctct
SELECT*FROM#temp_proc1
DROPTABLE#temp_proc1
dropprocedurefgw_proc1
execfgw_proc11,1
2,fgw_proc2
CREATEPROCEDUREfgw_proc2(@useridint,@beginint,@endint,@handledfloatOUTPUT)
AS
SETNOCOUNTON
SET@handled=0
DECLARE@cr_idint,@zh_idint,@statuschar(20),@to_statuschar(20),@cntint,@open_dateint
DECLAREcur_crzhCURSORFORSELECT*FROMAHD.dbo.FGW_CR_ZHwherecnt=@userid
OPENcur_crzh
FETCHcur_crzhINTO@cr_id,@zh_id,@status,@to_status,@cnt,@open_date
WHILE@@FETCH_STATUS=0
BEGIN
DECLARE@count2int
DECLAREcur_crzh2CURSORFORSELECTcount(*)FROMAHD.dbo.FGW_CR_ZHwherecr_id=@cr_idandopen_date>@beginandopen_date<@end
OPENcur_crzh2
FETCHcur_crzh2INTO@count2
CLOSEcur_crzh2
DEALLOCATEcur_crzh2
IF@count2!=0
SET@handled=@handled+1/@count2
FETCHNEXTFROMcur_crzhINTO@cr_id,@zh_id,@status,@to_status,@cnt,@open_date
END
CLOSEcur_crzh
DEALLOCATEcur_crzh
--SELECT@handled
dropprocedurefgw_proc2
execfgw_proc21,1,1
3,fgw_proc3
CREATEPROCEDUREfgw_proc3(@beginint,@endint)
AS
SETNOCOUNTON
DECLARE@cr_idint,@zh_idint,@cntint,@symchar(30),@time_stampint,@isOKint
CREATETABLE#temp_proc3
(
cr_idint,
zh_idint,
cntint,
isOKint
)
DECLAREcur_crzhsdCURSORFORSELECTcr.id,zh.id,zh.to_cnt,sd.sym,zh.time_stampFROMAHD.AHD.call_reqascrLEFTOUTERJOINAHD.AHD.ztr_hisaszhONcr.persid=zh.call_req_idLEFTOUTERJOINAHD.AHD.srv_descassdONcr.support_lev=sd.codeWHEREcr.type=Iandcr.open_date>@beginandcr.open_date<@endandzh.to_status=OP
OPENcur_crzhsd
FETCHcur_crzhsdINTO@cr_id,@zh_id,@cnt,@sym,@time_stamp
WHILE@@FETCH_STATUS=0
BEGIN
--get@handlethroughexecfgw_proc2
EXECfgw_proc4@zh_id,@sym,@time_stamp,@cntoutput,@isOKoutput
INSERTINTO#temp_proc3VALUES(@cr_id,@zh_id,@cnt,@isOK)
FETCHNEXTFROMcur_crzhsdINTO@cr_id,@zh_id,@cnt,@sym,@time_stamp
END
CLOSEcur_crzhsd
DEALLOCATEcur_crzhsd
SELECT*FROM#temp_proc3
DROPTABLE#temp_proc3
dropprocedurefgw_proc3
EXECfgw_proc31,1111111111
4,fgw_proc4
CREATEPROCEDUREfgw_proc4(@zh_idint,@levelchar(30),@time_stampint,@cntintOUTPUT,@isOKintOUTPUT)
AS
SETNOCOUNTON
SET@isOK=0
DECLAREcur_zhCURSORFORSELECTto_cnt,time_stampFROMAHD.AHD.ztr_hisWHEREid=@zh_idandto_statusin(L1WIP,L2WIP)andtime_stamp>@time_stamp
OPENcur_zh
DECLARE@time_stamp1int
SET@time_stamp1=0
FETCHcur_zhINTO@cnt,@time_stamp1
IF@time_stamp1!=0
BEGIN
IFCHARINDEX(一级,@level)ISNOTNULLANDCHARINDEX(一级,@level)!=0
BEGIN
if@time_stamp1-@time_stamp<600
SET@isOK=1
END
ELSEIFCHARINDEX(二级,@level)ISNOTNULLANDCHARINDEX(二级,@level)!=0
BEGIN
if@time_stamp1-@time_stamp<1800
SET@isOK=1
END
ELSEIFCHARINDEX(三级,@level)ISNOTNULLANDCHARINDEX(三级,@level)!=0
BEGIN
if@time_stamp1-@time_stamp<1800
SET@isOK=1
END
ELSEIFCHARINDEX(四级,@level)ISNOTNULLANDCHARINDEX(四级,@level)!=0
BEGIN
if@time_stamp1-@time_stamp<1800
SET@isOK=1
END
END
CLOSEcur_zh
DEALLOCATEcur_zh
--SELECT@isOK,@time_stamp1
dropprocedurefgw_proc4
execfgw_proc41,1,1,1,1
mysql的原来开发者又开发了MariaDB,MariaDB适合用来替代mysql吗 |
|