2022050902-UtilizationRateByHalfHour.sql 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675
  1. create proc UtilizationRateByHalfHour(@searchdatechar varchar(24),@CityCode varchar(10)) as
  2. begin
  3. declare @begintime datetime
  4. declare @endtime datetime
  5. declare @orgId varchar(40)
  6. declare @logintime_hour00 int,
  7. @logintime_hour01 int,
  8. @logintime_hour02 int,
  9. @logintime_hour03 int,
  10. @logintime_hour04 int,
  11. @logintime_hour05 int,
  12. @logintime_hour06 int,
  13. @logintime_hour07 int,
  14. @logintime_hour08 int,
  15. @logintime_hour09 int,
  16. @logintime_hour10 int,
  17. @logintime_hour11 int,
  18. @logintime_hour12 int,
  19. @logintime_hour13 int,
  20. @logintime_hour14 int,
  21. @logintime_hour15 int,
  22. @logintime_hour16 int,
  23. @logintime_hour17 int,
  24. @logintime_hour18 int,
  25. @logintime_hour19 int,
  26. @logintime_hour20 int,
  27. @logintime_hour21 int,
  28. @logintime_hour22 int,
  29. @logintime_hour23 int,
  30. @logintime_hour24 int,
  31. @logintime_hour25 int,
  32. @logintime_hour26 int,
  33. @logintime_hour27 int,
  34. @logintime_hour28 int,
  35. @logintime_hour29 int,
  36. @logintime_hour30 int,
  37. @logintime_hour31 int,
  38. @logintime_hour32 int,
  39. @logintime_hour33 int,
  40. @logintime_hour34 int,
  41. @logintime_hour35 int,
  42. @logintime_hour36 int,
  43. @logintime_hour37 int,
  44. @logintime_hour38 int,
  45. @logintime_hour39 int,
  46. @logintime_hour40 int,
  47. @logintime_hour41 int,
  48. @logintime_hour42 int,
  49. @logintime_hour43 int,
  50. @logintime_hour44 int,
  51. @logintime_hour45 int,
  52. @logintime_hour46 int,
  53. @logintime_hour47 int
  54. declare @acwtime_hour00 int,
  55. @acwtime_hour01 int,
  56. @acwtime_hour02 int,
  57. @acwtime_hour03 int,
  58. @acwtime_hour04 int,
  59. @acwtime_hour05 int,
  60. @acwtime_hour06 int,
  61. @acwtime_hour07 int,
  62. @acwtime_hour08 int,
  63. @acwtime_hour09 int,
  64. @acwtime_hour10 int,
  65. @acwtime_hour11 int,
  66. @acwtime_hour12 int,
  67. @acwtime_hour13 int,
  68. @acwtime_hour14 int,
  69. @acwtime_hour15 int,
  70. @acwtime_hour16 int,
  71. @acwtime_hour17 int,
  72. @acwtime_hour18 int,
  73. @acwtime_hour19 int,
  74. @acwtime_hour20 int,
  75. @acwtime_hour21 int,
  76. @acwtime_hour22 int,
  77. @acwtime_hour23 int,
  78. @acwtime_hour24 int,
  79. @acwtime_hour25 int,
  80. @acwtime_hour26 int,
  81. @acwtime_hour27 int,
  82. @acwtime_hour28 int,
  83. @acwtime_hour29 int,
  84. @acwtime_hour30 int,
  85. @acwtime_hour31 int,
  86. @acwtime_hour32 int,
  87. @acwtime_hour33 int,
  88. @acwtime_hour34 int,
  89. @acwtime_hour35 int,
  90. @acwtime_hour36 int,
  91. @acwtime_hour37 int,
  92. @acwtime_hour38 int,
  93. @acwtime_hour39 int,
  94. @acwtime_hour40 int,
  95. @acwtime_hour41 int,
  96. @acwtime_hour42 int,
  97. @acwtime_hour43 int,
  98. @acwtime_hour44 int,
  99. @acwtime_hour45 int,
  100. @acwtime_hour46 int,
  101. @acwtime_hour47 int
  102. declare @acdtime_hour00 int,
  103. @acdtime_hour01 int,
  104. @acdtime_hour02 int,
  105. @acdtime_hour03 int,
  106. @acdtime_hour04 int,
  107. @acdtime_hour05 int,
  108. @acdtime_hour06 int,
  109. @acdtime_hour07 int,
  110. @acdtime_hour08 int,
  111. @acdtime_hour09 int,
  112. @acdtime_hour10 int,
  113. @acdtime_hour11 int,
  114. @acdtime_hour12 int,
  115. @acdtime_hour13 int,
  116. @acdtime_hour14 int,
  117. @acdtime_hour15 int,
  118. @acdtime_hour16 int,
  119. @acdtime_hour17 int,
  120. @acdtime_hour18 int,
  121. @acdtime_hour19 int,
  122. @acdtime_hour20 int,
  123. @acdtime_hour21 int,
  124. @acdtime_hour22 int,
  125. @acdtime_hour23 int,
  126. @acdtime_hour24 int,
  127. @acdtime_hour25 int,
  128. @acdtime_hour26 int,
  129. @acdtime_hour27 int,
  130. @acdtime_hour28 int,
  131. @acdtime_hour29 int,
  132. @acdtime_hour30 int,
  133. @acdtime_hour31 int,
  134. @acdtime_hour32 int,
  135. @acdtime_hour33 int,
  136. @acdtime_hour34 int,
  137. @acdtime_hour35 int,
  138. @acdtime_hour36 int,
  139. @acdtime_hour37 int,
  140. @acdtime_hour38 int,
  141. @acdtime_hour39 int,
  142. @acdtime_hour40 int,
  143. @acdtime_hour41 int,
  144. @acdtime_hour42 int,
  145. @acdtime_hour43 int,
  146. @acdtime_hour44 int,
  147. @acdtime_hour45 int,
  148. @acdtime_hour46 int,
  149. @acdtime_hour47 int
  150. declare @ihour int
  151. set @begintime=convert(datetime,@searchdatechar)
  152. set @endtime=DATEADD(day,1,@begintime)
  153. --set @begintime='2022-05-09'
  154. --set @endtime='2022-05-10'
  155. set @orgId='b05d5ac9-82b6-4abe-b343-36ddc94672d1'
  156. if (@CityCode='SZ')
  157. set @orgId='2b568031-39a1-4117-9927-39b7ade19e66'
  158. if (@CityCode='JN')
  159. set @orgId='f454f95c-9ab2-4499-936f-e746195c7487'
  160. if OBJECT_ID('tempdb..#t_AgentLoginLog') is not null
  161. drop table #t_AgentLoginLog
  162. if OBJECT_ID('tempdb..#t_iagent') is not null
  163. drop table #t_iagent
  164. if OBJECT_ID('tempdb..#t_stationcallrecord') is not null
  165. drop table #t_stationcallrecord
  166. select * into #t_AgentLoginLog from AgentLoginLog where
  167. (
  168. (LoginTime >=@begintime and LoginTime < @endtime)
  169. or (LogoutTime >=@begintime and LogoutTime < @endtime)
  170. or (LoginTime >=@begintime and LoginTime < @endtime and LogoutTime is null)
  171. )
  172. and AgentID in (
  173. select distinct Agent.Agent from Agent with(nolock) join Org_Agent with(nolock) on
  174. Agent.AgentID=Org_Agent.AgentID join Organization with(nolock) on Org_Agent.OrgID=Organization.OrgID
  175. and Org_Agent.OrgID in (@orgId)
  176. )
  177. ;
  178. --某天每个小时的登录总时长
  179. set @ihour=1;
  180. select @logintime_hour00 = ISNULL(sum(DATEDIFF(ss,
  181. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  182. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  183. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  184. )),0)
  185. from #t_AgentLoginLog where
  186. (
  187. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  188. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  189. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  190. )
  191. ;
  192. set @ihour=@ihour+1;
  193. select @logintime_hour01 = ISNULL(sum(DATEDIFF(ss,
  194. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  195. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  196. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  197. )),0)
  198. from #t_AgentLoginLog where
  199. (
  200. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  201. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  202. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  203. )
  204. ;
  205. set @ihour=@ihour+1;
  206. select @logintime_hour02 = ISNULL(sum(DATEDIFF(ss,
  207. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  208. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  209. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  210. )),0)
  211. from #t_AgentLoginLog where
  212. (
  213. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  214. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  215. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  216. )
  217. ;
  218. set @ihour=@ihour+1;
  219. select @logintime_hour03 = ISNULL(sum(DATEDIFF(ss,
  220. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  221. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  222. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  223. )),0)
  224. from #t_AgentLoginLog where
  225. (
  226. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  227. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  228. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  229. )
  230. ;
  231. set @ihour=@ihour+1;
  232. select @logintime_hour04 = ISNULL(sum(DATEDIFF(ss,
  233. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  234. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  235. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  236. )),0)
  237. from #t_AgentLoginLog where
  238. (
  239. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  240. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  241. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  242. )
  243. ;
  244. set @ihour=@ihour+1;
  245. select @logintime_hour05 = ISNULL(sum(DATEDIFF(ss,
  246. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  247. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  248. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  249. )),0)
  250. from #t_AgentLoginLog where
  251. (
  252. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  253. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  254. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  255. )
  256. ;
  257. set @ihour=@ihour+1;
  258. select @logintime_hour06 = ISNULL(sum(DATEDIFF(ss,
  259. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  260. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  261. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  262. )),0)
  263. from #t_AgentLoginLog where
  264. (
  265. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  266. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  267. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  268. )
  269. ;
  270. set @ihour=@ihour+1;
  271. select @logintime_hour07 = ISNULL(sum(DATEDIFF(ss,
  272. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  273. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  274. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  275. )),0)
  276. from #t_AgentLoginLog where
  277. (
  278. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  279. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  280. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  281. )
  282. ;
  283. set @ihour=@ihour+1;
  284. select @logintime_hour08 = ISNULL(sum(DATEDIFF(ss,
  285. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  286. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  287. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  288. )),0)
  289. from #t_AgentLoginLog where
  290. (
  291. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  292. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  293. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  294. )
  295. ;
  296. set @ihour=@ihour+1;
  297. select @logintime_hour09 = ISNULL(sum(DATEDIFF(ss,
  298. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  299. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  300. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  301. )),0)
  302. from #t_AgentLoginLog where
  303. (
  304. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  305. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  306. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  307. )
  308. ;
  309. set @ihour=@ihour+1;
  310. select @logintime_hour10 = ISNULL(sum(DATEDIFF(ss,
  311. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  312. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  313. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  314. )),0)
  315. from #t_AgentLoginLog where
  316. (
  317. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  318. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  319. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  320. )
  321. ;
  322. set @ihour=@ihour+1;
  323. select @logintime_hour11 = ISNULL(sum(DATEDIFF(ss,
  324. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  325. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  326. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  327. )),0)
  328. from #t_AgentLoginLog where
  329. (
  330. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  331. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  332. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  333. )
  334. ;
  335. set @ihour=@ihour+1;
  336. select @logintime_hour12 = ISNULL(sum(DATEDIFF(ss,
  337. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  338. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  339. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  340. )),0)
  341. from #t_AgentLoginLog where
  342. (
  343. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  344. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  345. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  346. )
  347. ;
  348. set @ihour=@ihour+1;
  349. select @logintime_hour13 = ISNULL(sum(DATEDIFF(ss,
  350. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  351. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  352. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  353. )),0)
  354. from #t_AgentLoginLog where
  355. (
  356. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  357. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  358. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  359. )
  360. ;
  361. set @ihour=@ihour+1;
  362. select @logintime_hour14 = ISNULL(sum(DATEDIFF(ss,
  363. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  364. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  365. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  366. )),0)
  367. from #t_AgentLoginLog where
  368. (
  369. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  370. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  371. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  372. )
  373. ;
  374. set @ihour=@ihour+1;
  375. select @logintime_hour15 = ISNULL(sum(DATEDIFF(ss,
  376. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  377. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  378. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  379. )),0)
  380. from #t_AgentLoginLog where
  381. (
  382. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  383. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  384. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  385. )
  386. ;
  387. set @ihour=@ihour+1;
  388. select @logintime_hour16 = ISNULL(sum(DATEDIFF(ss,
  389. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  390. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  391. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  392. )),0)
  393. from #t_AgentLoginLog where
  394. (
  395. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  396. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  397. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  398. )
  399. ;
  400. set @ihour=@ihour+1;
  401. select @logintime_hour17 = ISNULL(sum(DATEDIFF(ss,
  402. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  403. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  404. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  405. )),0)
  406. from #t_AgentLoginLog where
  407. (
  408. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  409. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  410. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  411. )
  412. ;
  413. set @ihour=@ihour+1;
  414. select @logintime_hour18 = ISNULL(sum(DATEDIFF(ss,
  415. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  416. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  417. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  418. )),0)
  419. from #t_AgentLoginLog where
  420. (
  421. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  422. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  423. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  424. )
  425. ;
  426. set @ihour=@ihour+1;
  427. select @logintime_hour19 = ISNULL(sum(DATEDIFF(ss,
  428. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  429. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  430. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  431. )),0)
  432. from #t_AgentLoginLog where
  433. (
  434. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  435. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  436. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  437. )
  438. ;
  439. set @ihour=@ihour+1;
  440. select @logintime_hour20 = ISNULL(sum(DATEDIFF(ss,
  441. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  442. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  443. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  444. )),0)
  445. from #t_AgentLoginLog where
  446. (
  447. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  448. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  449. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  450. )
  451. ;
  452. set @ihour=@ihour+1;
  453. select @logintime_hour21 = ISNULL(sum(DATEDIFF(ss,
  454. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  455. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  456. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  457. )),0)
  458. from #t_AgentLoginLog where
  459. (
  460. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  461. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  462. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  463. )
  464. ;
  465. set @ihour=@ihour+1;
  466. select @logintime_hour22 = ISNULL(sum(DATEDIFF(ss,
  467. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  468. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  469. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  470. )),0)
  471. from #t_AgentLoginLog where
  472. (
  473. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  474. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  475. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  476. )
  477. ;
  478. set @ihour=@ihour+1;
  479. select @logintime_hour23 = ISNULL(sum(DATEDIFF(ss,
  480. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  481. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  482. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  483. )),0)
  484. from #t_AgentLoginLog where
  485. (
  486. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  487. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  488. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  489. )
  490. ;
  491. set @ihour=@ihour+1;
  492. select @logintime_hour24 = ISNULL(sum(DATEDIFF(ss,
  493. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  494. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  495. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  496. )),0)
  497. from #t_AgentLoginLog where
  498. (
  499. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  500. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  501. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  502. )
  503. ;
  504. set @ihour=@ihour+1;
  505. select @logintime_hour25 = ISNULL(sum(DATEDIFF(ss,
  506. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  507. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  508. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  509. )),0)
  510. from #t_AgentLoginLog where
  511. (
  512. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  513. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  514. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  515. )
  516. ;
  517. set @ihour=@ihour+1;
  518. select @logintime_hour26 = ISNULL(sum(DATEDIFF(ss,
  519. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  520. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  521. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  522. )),0)
  523. from #t_AgentLoginLog where
  524. (
  525. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  526. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  527. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  528. )
  529. ;
  530. set @ihour=@ihour+1;
  531. select @logintime_hour27 = ISNULL(sum(DATEDIFF(ss,
  532. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  533. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  534. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  535. )),0)
  536. from #t_AgentLoginLog where
  537. (
  538. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  539. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  540. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  541. )
  542. ;
  543. set @ihour=@ihour+1;
  544. select @logintime_hour28 = ISNULL(sum(DATEDIFF(ss,
  545. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  546. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  547. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  548. )),0)
  549. from #t_AgentLoginLog where
  550. (
  551. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  552. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  553. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  554. )
  555. ;
  556. set @ihour=@ihour+1;
  557. select @logintime_hour29 = ISNULL(sum(DATEDIFF(ss,
  558. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  559. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  560. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  561. )),0)
  562. from #t_AgentLoginLog where
  563. (
  564. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  565. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  566. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  567. )
  568. ;
  569. set @ihour=@ihour+1;
  570. select @logintime_hour30 = ISNULL(sum(DATEDIFF(ss,
  571. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  572. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  573. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  574. )),0)
  575. from #t_AgentLoginLog where
  576. (
  577. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  578. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  579. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  580. )
  581. ;
  582. set @ihour=@ihour+1;
  583. select @logintime_hour31 = ISNULL(sum(DATEDIFF(ss,
  584. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  585. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  586. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  587. )),0)
  588. from #t_AgentLoginLog where
  589. (
  590. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  591. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  592. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  593. )
  594. ;
  595. set @ihour=@ihour+1;
  596. select @logintime_hour32 = ISNULL(sum(DATEDIFF(ss,
  597. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  598. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  599. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  600. )),0)
  601. from #t_AgentLoginLog where
  602. (
  603. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  604. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  605. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  606. )
  607. ;
  608. set @ihour=@ihour+1;
  609. select @logintime_hour33 = ISNULL(sum(DATEDIFF(ss,
  610. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  611. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  612. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  613. )),0)
  614. from #t_AgentLoginLog where
  615. (
  616. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  617. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  618. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  619. )
  620. ;
  621. set @ihour=@ihour+1;
  622. select @logintime_hour34 = ISNULL(sum(DATEDIFF(ss,
  623. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  624. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  625. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  626. )),0)
  627. from #t_AgentLoginLog where
  628. (
  629. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  630. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  631. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  632. )
  633. ;
  634. set @ihour=@ihour+1;
  635. select @logintime_hour35 = ISNULL(sum(DATEDIFF(ss,
  636. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  637. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  638. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  639. )),0)
  640. from #t_AgentLoginLog where
  641. (
  642. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  643. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  644. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  645. )
  646. ;
  647. set @ihour=@ihour+1;
  648. select @logintime_hour36 = ISNULL(sum(DATEDIFF(ss,
  649. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  650. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  651. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  652. )),0)
  653. from #t_AgentLoginLog where
  654. (
  655. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  656. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  657. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  658. )
  659. ;
  660. set @ihour=@ihour+1;
  661. select @logintime_hour37 = ISNULL(sum(DATEDIFF(ss,
  662. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  663. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  664. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  665. )),0)
  666. from #t_AgentLoginLog where
  667. (
  668. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  669. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  670. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  671. )
  672. ;
  673. set @ihour=@ihour+1;
  674. select @logintime_hour38 = ISNULL(sum(DATEDIFF(ss,
  675. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  676. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  677. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  678. )),0)
  679. from #t_AgentLoginLog where
  680. (
  681. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  682. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  683. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  684. )
  685. ;
  686. set @ihour=@ihour+1;
  687. select @logintime_hour39 = ISNULL(sum(DATEDIFF(ss,
  688. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  689. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  690. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  691. )),0)
  692. from #t_AgentLoginLog where
  693. (
  694. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  695. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  696. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  697. )
  698. ;
  699. set @ihour=@ihour+1;
  700. select @logintime_hour40 = ISNULL(sum(DATEDIFF(ss,
  701. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  702. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  703. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  704. )),0)
  705. from #t_AgentLoginLog where
  706. (
  707. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  708. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  709. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  710. )
  711. ;
  712. set @ihour=@ihour+1;
  713. select @logintime_hour41 = ISNULL(sum(DATEDIFF(ss,
  714. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  715. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  716. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  717. )),0)
  718. from #t_AgentLoginLog where
  719. (
  720. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  721. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  722. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  723. )
  724. ;
  725. set @ihour=@ihour+1;
  726. select @logintime_hour42 = ISNULL(sum(DATEDIFF(ss,
  727. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  728. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  729. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  730. )),0)
  731. from #t_AgentLoginLog where
  732. (
  733. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  734. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  735. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  736. )
  737. ;
  738. set @ihour=@ihour+1;
  739. select @logintime_hour43 = ISNULL(sum(DATEDIFF(ss,
  740. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  741. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  742. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  743. )),0)
  744. from #t_AgentLoginLog where
  745. (
  746. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  747. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  748. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  749. )
  750. ;
  751. set @ihour=@ihour+1;
  752. select @logintime_hour44 = ISNULL(sum(DATEDIFF(ss,
  753. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  754. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  755. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  756. )),0)
  757. from #t_AgentLoginLog where
  758. (
  759. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  760. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  761. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  762. )
  763. ;
  764. set @ihour=@ihour+1;
  765. select @logintime_hour45 = ISNULL(sum(DATEDIFF(ss,
  766. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  767. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  768. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  769. )),0)
  770. from #t_AgentLoginLog where
  771. (
  772. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  773. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  774. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  775. )
  776. ;
  777. set @ihour=@ihour+1;
  778. select @logintime_hour46 = ISNULL(sum(DATEDIFF(ss,
  779. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  780. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  781. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  782. )),0)
  783. from #t_AgentLoginLog where
  784. (
  785. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  786. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  787. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  788. )
  789. ;
  790. set @ihour=@ihour+1;
  791. select @logintime_hour47 = ISNULL(sum(DATEDIFF(ss,
  792. case when LoginTime<@begintime then CONVERT(datetime,@begintime) else LoginTime end,
  793. case when LogoutTime>dateadd(MINUTE,@ihour*30,@begintime) then dateadd(MINUTE,@ihour*30,@begintime)
  794. when LogoutTime is null then dateadd(MINUTE,@ihour*30,@begintime) else LogoutTime end
  795. )),0)
  796. from #t_AgentLoginLog where
  797. (
  798. (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime))
  799. or (LogoutTime >=@begintime and LogoutTime < dateadd(MINUTE,@ihour*30,@begintime))
  800. or (LoginTime >=@begintime and LoginTime < dateadd(MINUTE,@ihour*30,@begintime) and LogoutTime is null)
  801. )
  802. ;
  803. --每小时总的话后总时长
  804. select * into #t_iagent
  805. from iagent where 1=1
  806. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime))
  807. and logid in
  808. (
  809. select distinct Agent.Agent from Agent with(nolock) join Org_Agent with(nolock) on
  810. Agent.AgentID=Org_Agent.AgentID join Organization with(nolock) on Org_Agent.OrgID=Organization.OrgID
  811. and Org_Agent.OrgID in (@orgId)
  812. )
  813. set @ihour=1;
  814. select @acwtime_hour00= isnull(sum(i_acwtime),0)
  815. from #t_iagent where 1=1
  816. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  817. set @ihour=@ihour+1;
  818. select @acwtime_hour01= isnull(sum(i_acwtime),0)
  819. from #t_iagent where 1=1
  820. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  821. set @ihour=@ihour+1;
  822. select @acwtime_hour02= isnull(sum(i_acwtime),0)
  823. from #t_iagent where 1=1
  824. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  825. set @ihour=@ihour+1;
  826. select @acwtime_hour03= isnull(sum(i_acwtime),0)
  827. from #t_iagent where 1=1
  828. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  829. set @ihour=@ihour+1;
  830. select @acwtime_hour04= isnull(sum(i_acwtime),0)
  831. from #t_iagent where 1=1
  832. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  833. set @ihour=@ihour+1;
  834. select @acwtime_hour05= isnull(sum(i_acwtime),0)
  835. from #t_iagent where 1=1
  836. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  837. set @ihour=@ihour+1;
  838. select @acwtime_hour06= isnull(sum(i_acwtime),0)
  839. from #t_iagent where 1=1
  840. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  841. set @ihour=@ihour+1;
  842. select @acwtime_hour07= isnull(sum(i_acwtime),0)
  843. from #t_iagent where 1=1
  844. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  845. set @ihour=@ihour+1;
  846. select @acwtime_hour08= isnull(sum(i_acwtime),0)
  847. from #t_iagent where 1=1
  848. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  849. set @ihour=@ihour+1;
  850. select @acwtime_hour09= isnull(sum(i_acwtime),0)
  851. from #t_iagent where 1=1
  852. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  853. set @ihour=@ihour+1;
  854. select @acwtime_hour10= isnull(sum(i_acwtime),0)
  855. from #t_iagent where 1=1
  856. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  857. set @ihour=@ihour+1;
  858. select @acwtime_hour11= isnull(sum(i_acwtime),0)
  859. from #t_iagent where 1=1
  860. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  861. set @ihour=@ihour+1;
  862. select @acwtime_hour12= isnull(sum(i_acwtime),0)
  863. from #t_iagent where 1=1
  864. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  865. set @ihour=@ihour+1;
  866. select @acwtime_hour13= isnull(sum(i_acwtime),0)
  867. from #t_iagent where 1=1
  868. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  869. set @ihour=@ihour+1;
  870. select @acwtime_hour14= isnull(sum(i_acwtime),0)
  871. from #t_iagent where 1=1
  872. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  873. set @ihour=@ihour+1;
  874. select @acwtime_hour15= isnull(sum(i_acwtime),0)
  875. from #t_iagent where 1=1
  876. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  877. set @ihour=@ihour+1;
  878. select @acwtime_hour16= isnull(sum(i_acwtime),0)
  879. from #t_iagent where 1=1
  880. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  881. set @ihour=@ihour+1;
  882. select @acwtime_hour17= isnull(sum(i_acwtime),0)
  883. from #t_iagent where 1=1
  884. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  885. set @ihour=@ihour+1;
  886. select @acwtime_hour18= isnull(sum(i_acwtime),0)
  887. from #t_iagent where 1=1
  888. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  889. set @ihour=@ihour+1;
  890. select @acwtime_hour19= isnull(sum(i_acwtime),0)
  891. from #t_iagent where 1=1
  892. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  893. set @ihour=@ihour+1;
  894. select @acwtime_hour20= isnull(sum(i_acwtime),0)
  895. from #t_iagent where 1=1
  896. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  897. set @ihour=@ihour+1;
  898. select @acwtime_hour21= isnull(sum(i_acwtime),0)
  899. from #t_iagent where 1=1
  900. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  901. set @ihour=@ihour+1;
  902. select @acwtime_hour22= isnull(sum(i_acwtime),0)
  903. from #t_iagent where 1=1
  904. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  905. set @ihour=@ihour+1;
  906. select @acwtime_hour23= isnull(sum(i_acwtime),0)
  907. from #t_iagent where 1=1
  908. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  909. set @ihour=@ihour+1;
  910. select @acwtime_hour24= isnull(sum(i_acwtime),0)
  911. from #t_iagent where 1=1
  912. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  913. set @ihour=@ihour+1;
  914. select @acwtime_hour25= isnull(sum(i_acwtime),0)
  915. from #t_iagent where 1=1
  916. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  917. set @ihour=@ihour+1;
  918. select @acwtime_hour26= isnull(sum(i_acwtime),0)
  919. from #t_iagent where 1=1
  920. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  921. set @ihour=@ihour+1;
  922. select @acwtime_hour27= isnull(sum(i_acwtime),0)
  923. from #t_iagent where 1=1
  924. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  925. set @ihour=@ihour+1;
  926. select @acwtime_hour28= isnull(sum(i_acwtime),0)
  927. from #t_iagent where 1=1
  928. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  929. set @ihour=@ihour+1;
  930. select @acwtime_hour29= isnull(sum(i_acwtime),0)
  931. from #t_iagent where 1=1
  932. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  933. set @ihour=@ihour+1;
  934. select @acwtime_hour30= isnull(sum(i_acwtime),0)
  935. from #t_iagent where 1=1
  936. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  937. set @ihour=@ihour+1;
  938. select @acwtime_hour31= isnull(sum(i_acwtime),0)
  939. from #t_iagent where 1=1
  940. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  941. set @ihour=@ihour+1;
  942. select @acwtime_hour32= isnull(sum(i_acwtime),0)
  943. from #t_iagent where 1=1
  944. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  945. set @ihour=@ihour+1;
  946. select @acwtime_hour33= isnull(sum(i_acwtime),0)
  947. from #t_iagent where 1=1
  948. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  949. set @ihour=@ihour+1;
  950. select @acwtime_hour34= isnull(sum(i_acwtime),0)
  951. from #t_iagent where 1=1
  952. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  953. set @ihour=@ihour+1;
  954. select @acwtime_hour35= isnull(sum(i_acwtime),0)
  955. from #t_iagent where 1=1
  956. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  957. set @ihour=@ihour+1;
  958. select @acwtime_hour36= isnull(sum(i_acwtime),0)
  959. from #t_iagent where 1=1
  960. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  961. set @ihour=@ihour+1;
  962. select @acwtime_hour37= isnull(sum(i_acwtime),0)
  963. from #t_iagent where 1=1
  964. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  965. set @ihour=@ihour+1;
  966. select @acwtime_hour38= isnull(sum(i_acwtime),0)
  967. from #t_iagent where 1=1
  968. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  969. set @ihour=@ihour+1;
  970. select @acwtime_hour39= isnull(sum(i_acwtime),0)
  971. from #t_iagent where 1=1
  972. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  973. set @ihour=@ihour+1;
  974. select @acwtime_hour40= isnull(sum(i_acwtime),0)
  975. from #t_iagent where 1=1
  976. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  977. set @ihour=@ihour+1;
  978. select @acwtime_hour41= isnull(sum(i_acwtime),0)
  979. from #t_iagent where 1=1
  980. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  981. set @ihour=@ihour+1;
  982. select @acwtime_hour42= isnull(sum(i_acwtime),0)
  983. from #t_iagent where 1=1
  984. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  985. set @ihour=@ihour+1;
  986. select @acwtime_hour43= isnull(sum(i_acwtime),0)
  987. from #t_iagent where 1=1
  988. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  989. set @ihour=@ihour+1;
  990. select @acwtime_hour44= isnull(sum(i_acwtime),0)
  991. from #t_iagent where 1=1
  992. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  993. set @ihour=@ihour+1;
  994. select @acwtime_hour45= isnull(sum(i_acwtime),0)
  995. from #t_iagent where 1=1
  996. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  997. set @ihour=@ihour+1;
  998. select @acwtime_hour46= isnull(sum(i_acwtime),0)
  999. from #t_iagent where 1=1
  1000. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  1001. set @ihour=@ihour+1;
  1002. select @acwtime_hour47= isnull(sum(i_acwtime),0)
  1003. from #t_iagent where 1=1
  1004. and (row_date >=@begintime and row_date < dateadd(MINUTE,@ihour*30,@begintime));
  1005. --每小时总的通话总时长
  1006. select * into #t_stationcallrecord
  1007. from stationcallrecord with(nolock)
  1008. where 1=1
  1009. and (End_Time >=@begintime and End_Time <@endtime)
  1010. and split in ('841001','841002','841009','841012','841013','842030','841041','841301','841302','841303','841304','841305','841306','841307','841311','841312','841313','841314','841315','841316','841317','841341','841342','841343','841344','841345','841346','841347','841321','841322','841323','841324','841325','841326','841327','841331','841332','841333','841334','841335','841336','841337','841351','841352','841353','841354','841355','841356','841357')
  1011. and calldirect=1
  1012. and split != ''
  1013. and AgentID in
  1014. (
  1015. select distinct Agent.Agent from Agent with(nolock) join Org_Agent with(nolock) on
  1016. Agent.AgentID=Org_Agent.AgentID join Organization with(nolock) on Org_Agent.OrgID=Organization.OrgID
  1017. and Org_Agent.OrgID in (@orgId)
  1018. );
  1019. set @ihour=1;
  1020. select @acdtime_hour00=
  1021. isnull(sum(talk_dur),0)
  1022. from #t_stationcallrecord
  1023. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1024. ;
  1025. set @ihour=@ihour+1;
  1026. select @acdtime_hour01=
  1027. isnull(sum(talk_dur),0)
  1028. from #t_stationcallrecord
  1029. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1030. ;
  1031. set @ihour=@ihour+1;
  1032. select @acdtime_hour02=
  1033. isnull(sum(talk_dur),0)
  1034. from #t_stationcallrecord
  1035. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1036. ;
  1037. set @ihour=@ihour+1;
  1038. select @acdtime_hour03=
  1039. isnull(sum(talk_dur),0)
  1040. from #t_stationcallrecord
  1041. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1042. ;
  1043. set @ihour=@ihour+1;
  1044. select @acdtime_hour04=
  1045. isnull(sum(talk_dur),0)
  1046. from #t_stationcallrecord
  1047. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1048. ;
  1049. set @ihour=@ihour+1;
  1050. select @acdtime_hour05=
  1051. isnull(sum(talk_dur),0)
  1052. from #t_stationcallrecord
  1053. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1054. ;
  1055. set @ihour=@ihour+1;
  1056. select @acdtime_hour06=
  1057. isnull(sum(talk_dur),0)
  1058. from #t_stationcallrecord
  1059. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1060. ;
  1061. set @ihour=@ihour+1;
  1062. select @acdtime_hour07=
  1063. isnull(sum(talk_dur),0)
  1064. from #t_stationcallrecord
  1065. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1066. ;
  1067. set @ihour=@ihour+1;
  1068. select @acdtime_hour08=
  1069. isnull(sum(talk_dur),0)
  1070. from #t_stationcallrecord
  1071. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1072. ;
  1073. set @ihour=@ihour+1;
  1074. select @acdtime_hour09=
  1075. isnull(sum(talk_dur),0)
  1076. from #t_stationcallrecord
  1077. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1078. ;
  1079. set @ihour=@ihour+1;
  1080. select @acdtime_hour10=
  1081. isnull(sum(talk_dur),0)
  1082. from #t_stationcallrecord
  1083. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1084. ;
  1085. set @ihour=@ihour+1;
  1086. select @acdtime_hour11=
  1087. isnull(sum(talk_dur),0)
  1088. from #t_stationcallrecord
  1089. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1090. ;
  1091. set @ihour=@ihour+1;
  1092. select @acdtime_hour12=
  1093. isnull(sum(talk_dur),0)
  1094. from #t_stationcallrecord
  1095. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1096. ;
  1097. set @ihour=@ihour+1;
  1098. select @acdtime_hour13=
  1099. isnull(sum(talk_dur),0)
  1100. from #t_stationcallrecord
  1101. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1102. ;
  1103. set @ihour=@ihour+1;
  1104. select @acdtime_hour14=
  1105. isnull(sum(talk_dur),0)
  1106. from #t_stationcallrecord
  1107. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1108. ;
  1109. set @ihour=@ihour+1;
  1110. select @acdtime_hour15=
  1111. isnull(sum(talk_dur),0)
  1112. from #t_stationcallrecord
  1113. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1114. ;
  1115. set @ihour=@ihour+1;
  1116. select @acdtime_hour16=
  1117. isnull(sum(talk_dur),0)
  1118. from #t_stationcallrecord
  1119. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1120. ;
  1121. set @ihour=@ihour+1;
  1122. select @acdtime_hour17=
  1123. isnull(sum(talk_dur),0)
  1124. from #t_stationcallrecord
  1125. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1126. ;
  1127. set @ihour=@ihour+1;
  1128. select @acdtime_hour18=
  1129. isnull(sum(talk_dur),0)
  1130. from #t_stationcallrecord
  1131. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1132. ;
  1133. set @ihour=@ihour+1;
  1134. select @acdtime_hour19=
  1135. isnull(sum(talk_dur),0)
  1136. from #t_stationcallrecord
  1137. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1138. ;
  1139. set @ihour=@ihour+1;
  1140. select @acdtime_hour20=
  1141. isnull(sum(talk_dur),0)
  1142. from #t_stationcallrecord
  1143. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1144. ;
  1145. set @ihour=@ihour+1;
  1146. select @acdtime_hour21=
  1147. isnull(sum(talk_dur),0)
  1148. from #t_stationcallrecord
  1149. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1150. ;
  1151. set @ihour=@ihour+1;
  1152. select @acdtime_hour22=
  1153. isnull(sum(talk_dur),0)
  1154. from #t_stationcallrecord
  1155. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1156. ;
  1157. set @ihour=@ihour+1;
  1158. select @acdtime_hour23=
  1159. isnull(sum(talk_dur),0)
  1160. from #t_stationcallrecord
  1161. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1162. ;
  1163. set @ihour=@ihour+1;
  1164. select @acdtime_hour24=
  1165. isnull(sum(talk_dur),0)
  1166. from #t_stationcallrecord
  1167. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1168. ;
  1169. set @ihour=@ihour+1;
  1170. select @acdtime_hour25=
  1171. isnull(sum(talk_dur),0)
  1172. from #t_stationcallrecord
  1173. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1174. ;
  1175. set @ihour=@ihour+1;
  1176. select @acdtime_hour26=
  1177. isnull(sum(talk_dur),0)
  1178. from #t_stationcallrecord
  1179. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1180. ;
  1181. set @ihour=@ihour+1;
  1182. select @acdtime_hour27=
  1183. isnull(sum(talk_dur),0)
  1184. from #t_stationcallrecord
  1185. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1186. ;
  1187. set @ihour=@ihour+1;
  1188. select @acdtime_hour28=
  1189. isnull(sum(talk_dur),0)
  1190. from #t_stationcallrecord
  1191. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1192. ;
  1193. set @ihour=@ihour+1;
  1194. select @acdtime_hour29=
  1195. isnull(sum(talk_dur),0)
  1196. from #t_stationcallrecord
  1197. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1198. ;
  1199. set @ihour=@ihour+1;
  1200. select @acdtime_hour30=
  1201. isnull(sum(talk_dur),0)
  1202. from #t_stationcallrecord
  1203. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1204. ;
  1205. set @ihour=@ihour+1;
  1206. select @acdtime_hour31=
  1207. isnull(sum(talk_dur),0)
  1208. from #t_stationcallrecord
  1209. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1210. ;
  1211. set @ihour=@ihour+1;
  1212. select @acdtime_hour32=
  1213. isnull(sum(talk_dur),0)
  1214. from #t_stationcallrecord
  1215. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1216. ;
  1217. set @ihour=@ihour+1;
  1218. select @acdtime_hour33=
  1219. isnull(sum(talk_dur),0)
  1220. from #t_stationcallrecord
  1221. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1222. ;
  1223. set @ihour=@ihour+1;
  1224. select @acdtime_hour34=
  1225. isnull(sum(talk_dur),0)
  1226. from #t_stationcallrecord
  1227. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1228. ;
  1229. set @ihour=@ihour+1;
  1230. select @acdtime_hour35=
  1231. isnull(sum(talk_dur),0)
  1232. from #t_stationcallrecord
  1233. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1234. ;
  1235. set @ihour=@ihour+1;
  1236. select @acdtime_hour36=
  1237. isnull(sum(talk_dur),0)
  1238. from #t_stationcallrecord
  1239. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1240. ;
  1241. set @ihour=@ihour+1;
  1242. select @acdtime_hour37=
  1243. isnull(sum(talk_dur),0)
  1244. from #t_stationcallrecord
  1245. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1246. ;
  1247. set @ihour=@ihour+1;
  1248. select @acdtime_hour38=
  1249. isnull(sum(talk_dur),0)
  1250. from #t_stationcallrecord
  1251. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1252. ;
  1253. set @ihour=@ihour+1;
  1254. select @acdtime_hour39=
  1255. isnull(sum(talk_dur),0)
  1256. from #t_stationcallrecord
  1257. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1258. ;
  1259. set @ihour=@ihour+1;
  1260. select @acdtime_hour40=
  1261. isnull(sum(talk_dur),0)
  1262. from #t_stationcallrecord
  1263. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1264. ;
  1265. set @ihour=@ihour+1;
  1266. select @acdtime_hour41=
  1267. isnull(sum(talk_dur),0)
  1268. from #t_stationcallrecord
  1269. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1270. ;
  1271. set @ihour=@ihour+1;
  1272. select @acdtime_hour42=
  1273. isnull(sum(talk_dur),0)
  1274. from #t_stationcallrecord
  1275. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1276. ;
  1277. set @ihour=@ihour+1;
  1278. select @acdtime_hour43=
  1279. isnull(sum(talk_dur),0)
  1280. from #t_stationcallrecord
  1281. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1282. ;
  1283. set @ihour=@ihour+1;
  1284. select @acdtime_hour44=
  1285. isnull(sum(talk_dur),0)
  1286. from #t_stationcallrecord
  1287. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1288. ;
  1289. set @ihour=@ihour+1;
  1290. select @acdtime_hour45=
  1291. isnull(sum(talk_dur),0)
  1292. from #t_stationcallrecord
  1293. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1294. ;
  1295. set @ihour=@ihour+1;
  1296. select @acdtime_hour46=
  1297. isnull(sum(talk_dur),0)
  1298. from #t_stationcallrecord
  1299. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1300. ;
  1301. set @ihour=@ihour+1;
  1302. select @acdtime_hour47=
  1303. isnull(sum(talk_dur),0)
  1304. from #t_stationcallrecord
  1305. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1306. ;
  1307. select case when @logintime_hour00=0 then 0 else round(cast( (@acdtime_hour00+@acwtime_hour00) as float)/@logintime_hour00,4) end as UtilizationRate00,
  1308. case when @logintime_hour01=0 then 0 else round(cast( (@acdtime_hour01+@acwtime_hour01) as float)/@logintime_hour01,4) end as UtilizationRate01,
  1309. case when @logintime_hour02=0 then 0 else round(cast( (@acdtime_hour02+@acwtime_hour02) as float)/@logintime_hour02,4) end as UtilizationRate02,
  1310. case when @logintime_hour03=0 then 0 else round(cast( (@acdtime_hour03+@acwtime_hour03) as float)/@logintime_hour03,4) end as UtilizationRate03,
  1311. case when @logintime_hour04=0 then 0 else round(cast( (@acdtime_hour04+@acwtime_hour04) as float)/@logintime_hour04,4) end as UtilizationRate04,
  1312. case when @logintime_hour05=0 then 0 else round(cast( (@acdtime_hour05+@acwtime_hour05) as float)/@logintime_hour05,4) end as UtilizationRate05,
  1313. case when @logintime_hour06=0 then 0 else round(cast( (@acdtime_hour06+@acwtime_hour06) as float)/@logintime_hour06,4) end as UtilizationRate06,
  1314. case when @logintime_hour07=0 then 0 else round(cast( (@acdtime_hour07+@acwtime_hour07) as float)/@logintime_hour07,4) end as UtilizationRate07,
  1315. case when @logintime_hour08=0 then 0 else round(cast( (@acdtime_hour08+@acwtime_hour08) as float)/@logintime_hour08,4) end as UtilizationRate08,
  1316. case when @logintime_hour09=0 then 0 else round(cast( (@acdtime_hour09+@acwtime_hour09) as float)/@logintime_hour09,4) end as UtilizationRate09,
  1317. case when @logintime_hour10=0 then 0 else round(cast( (@acdtime_hour10+@acwtime_hour10) as float)/@logintime_hour10,4) end as UtilizationRate10,
  1318. case when @logintime_hour11=0 then 0 else round(cast( (@acdtime_hour11+@acwtime_hour11) as float)/@logintime_hour11,4) end as UtilizationRate11,
  1319. case when @logintime_hour12=0 then 0 else round(cast( (@acdtime_hour12+@acwtime_hour12) as float)/@logintime_hour12,4) end as UtilizationRate12,
  1320. case when @logintime_hour13=0 then 0 else round(cast( (@acdtime_hour13+@acwtime_hour13) as float)/@logintime_hour13,4) end as UtilizationRate13,
  1321. case when @logintime_hour14=0 then 0 else round(cast( (@acdtime_hour14+@acwtime_hour14) as float)/@logintime_hour14,4) end as UtilizationRate14,
  1322. case when @logintime_hour15=0 then 0 else round(cast( (@acdtime_hour15+@acwtime_hour15) as float)/@logintime_hour15,4) end as UtilizationRate15,
  1323. case when @logintime_hour16=0 then 0 else round(cast( (@acdtime_hour16+@acwtime_hour16) as float)/@logintime_hour16,4) end as UtilizationRate16,
  1324. case when @logintime_hour17=0 then 0 else round(cast( (@acdtime_hour17+@acwtime_hour17) as float)/@logintime_hour17,4) end as UtilizationRate17,
  1325. case when @logintime_hour18=0 then 0 else round(cast( (@acdtime_hour18+@acwtime_hour18) as float)/@logintime_hour18,4) end as UtilizationRate18,
  1326. case when @logintime_hour19=0 then 0 else round(cast( (@acdtime_hour19+@acwtime_hour19) as float)/@logintime_hour19,4) end as UtilizationRate19,
  1327. case when @logintime_hour20=0 then 0 else round(cast( (@acdtime_hour20+@acwtime_hour20) as float)/@logintime_hour20,4) end as UtilizationRate20,
  1328. case when @logintime_hour21=0 then 0 else round(cast( (@acdtime_hour21+@acwtime_hour21) as float)/@logintime_hour21,4) end as UtilizationRate21,
  1329. case when @logintime_hour22=0 then 0 else round(cast( (@acdtime_hour22+@acwtime_hour22) as float)/@logintime_hour22,4) end as UtilizationRate22,
  1330. case when @logintime_hour23=0 then 0 else round(cast( (@acdtime_hour23+@acwtime_hour23) as float)/@logintime_hour23,4) end as UtilizationRate23,
  1331. case when @logintime_hour24=0 then 0 else round(cast( (@acdtime_hour24+@acwtime_hour24) as float)/@logintime_hour24,4) end as UtilizationRate24,
  1332. case when @logintime_hour25=0 then 0 else round(cast( (@acdtime_hour25+@acwtime_hour25) as float)/@logintime_hour25,4) end as UtilizationRate25,
  1333. case when @logintime_hour26=0 then 0 else round(cast( (@acdtime_hour26+@acwtime_hour26) as float)/@logintime_hour26,4) end as UtilizationRate26,
  1334. case when @logintime_hour27=0 then 0 else round(cast( (@acdtime_hour27+@acwtime_hour27) as float)/@logintime_hour27,4) end as UtilizationRate27,
  1335. case when @logintime_hour28=0 then 0 else round(cast( (@acdtime_hour28+@acwtime_hour28) as float)/@logintime_hour28,4) end as UtilizationRate28,
  1336. case when @logintime_hour29=0 then 0 else round(cast( (@acdtime_hour29+@acwtime_hour29) as float)/@logintime_hour29,4) end as UtilizationRate29,
  1337. case when @logintime_hour30=0 then 0 else round(cast( (@acdtime_hour30+@acwtime_hour30) as float)/@logintime_hour30,4) end as UtilizationRate30,
  1338. case when @logintime_hour31=0 then 0 else round(cast( (@acdtime_hour31+@acwtime_hour31) as float)/@logintime_hour31,4) end as UtilizationRate31,
  1339. case when @logintime_hour32=0 then 0 else round(cast( (@acdtime_hour32+@acwtime_hour32) as float)/@logintime_hour32,4) end as UtilizationRate32,
  1340. case when @logintime_hour33=0 then 0 else round(cast( (@acdtime_hour33+@acwtime_hour33) as float)/@logintime_hour33,4) end as UtilizationRate33,
  1341. case when @logintime_hour34=0 then 0 else round(cast( (@acdtime_hour34+@acwtime_hour34) as float)/@logintime_hour34,4) end as UtilizationRate34,
  1342. case when @logintime_hour35=0 then 0 else round(cast( (@acdtime_hour35+@acwtime_hour35) as float)/@logintime_hour35,4) end as UtilizationRate35,
  1343. case when @logintime_hour36=0 then 0 else round(cast( (@acdtime_hour36+@acwtime_hour36) as float)/@logintime_hour36,4) end as UtilizationRate36,
  1344. case when @logintime_hour37=0 then 0 else round(cast( (@acdtime_hour37+@acwtime_hour37) as float)/@logintime_hour37,4) end as UtilizationRate37,
  1345. case when @logintime_hour38=0 then 0 else round(cast( (@acdtime_hour38+@acwtime_hour38) as float)/@logintime_hour38,4) end as UtilizationRate38,
  1346. case when @logintime_hour39=0 then 0 else round(cast( (@acdtime_hour39+@acwtime_hour39) as float)/@logintime_hour39,4) end as UtilizationRate39,
  1347. case when @logintime_hour40=0 then 0 else round(cast( (@acdtime_hour40+@acwtime_hour40) as float)/@logintime_hour40,4) end as UtilizationRate40,
  1348. case when @logintime_hour41=0 then 0 else round(cast( (@acdtime_hour41+@acwtime_hour41) as float)/@logintime_hour41,4) end as UtilizationRate41,
  1349. case when @logintime_hour42=0 then 0 else round(cast( (@acdtime_hour42+@acwtime_hour42) as float)/@logintime_hour42,4) end as UtilizationRate42,
  1350. case when @logintime_hour43=0 then 0 else round(cast( (@acdtime_hour43+@acwtime_hour43) as float)/@logintime_hour43,4) end as UtilizationRate43,
  1351. case when @logintime_hour44=0 then 0 else round(cast( (@acdtime_hour44+@acwtime_hour44) as float)/@logintime_hour44,4) end as UtilizationRate44,
  1352. case when @logintime_hour45=0 then 0 else round(cast( (@acdtime_hour45+@acwtime_hour45) as float)/@logintime_hour45,4) end as UtilizationRate45,
  1353. case when @logintime_hour46=0 then 0 else round(cast( (@acdtime_hour46+@acwtime_hour46) as float)/@logintime_hour46,4) end as UtilizationRate46,
  1354. case when @logintime_hour47=0 then 0 else round(cast( (@acdtime_hour47+@acwtime_hour47) as float)/@logintime_hour47,4) end as UtilizationRate47
  1355. if OBJECT_ID('tempdb..#t_AgentLoginLog') is not null
  1356. drop table #t_AgentLoginLog
  1357. if OBJECT_ID('tempdb..#t_iagent') is not null
  1358. drop table #t_iagent
  1359. if OBJECT_ID('tempdb..#t_stationcallrecord') is not null
  1360. drop table #t_stationcallrecord
  1361. end