MSSQL编程:存储历程---理论
用一个库#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吗 在select语句中可以使用groupby子句将行划分成较小的组,然后,使用聚组函数返回每一个组的汇总信息,另外,可以使用having子句限制返回的结果集。 分区表是个亮点!从分区表也能看出微软要做大作强SQLServer的信心。资料很多,这里不详细说。但是重点了解的是:现在的SQLServer2005的表,都是默认为分区表的。因为它要支持滑动窗口的这个特性。这种特性对历史数据和实时数据的处理是很有帮助的。 SP4是一个累积性的ServicePack,包含自以前的ServicePack发布以来所有的修补程序(包括MS03-031安全公告)。 sqlserver的痛苦之处在于有用文档的匮乏,很多只是表明的东西 现在是在考虑:如果写到服务器端,我一下搞他个10个存储过程导过去,那久之服务器不就成垃圾箱了吗?即便优化了我的中间层. 从项目平台的选择上讲,我们关心的,应该是一款产品能不能满足任务需求,而不是网上怎么说。 SQLServer的异构移植功能个人感觉最好了。(如果对比过SQLServer的链接服务器和Oracle的透明网关的朋友会发现SQLServer的sp_addlinkedserver(openquery)异构数据库系列比Oracle真是强太多了。) 但换公司用MSSQL2K感觉自己好像根本就不了解MSSQL。什么DTS触发器以前根本没用过。
页:
[1]