2022051201-UtilizationRateByHalfHour.sql 143 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133
  1. alter 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. declare
  152. @i_acwtime1 int,
  153. @i_acwtime2 int,
  154. @i_acwtime3 int,
  155. @i_acwtime4 int,
  156. @i_acwtime int
  157. declare
  158. @i_stafftime1 int,
  159. @i_stafftime2 int,
  160. @i_stafftime3 int,
  161. @i_stafftime4 int,
  162. @i_stafftime int
  163. set @begintime=convert(datetime,@searchdatechar)
  164. set @endtime=DATEADD(day,1,@begintime)
  165. --set @begintime='2022-05-09'
  166. --set @endtime='2022-05-10'
  167. set @orgId='b05d5ac9-82b6-4abe-b343-36ddc94672d1'
  168. if (@CityCode='SZ')
  169. set @orgId='2b568031-39a1-4117-9927-39b7ade19e66'
  170. if (@CityCode='JN')
  171. set @orgId='f454f95c-9ab2-4499-936f-e746195c7487'
  172. if OBJECT_ID('tempdb..#compute_agentloginlog') is not null
  173. drop table #compute_agentloginlog
  174. if OBJECT_ID('tempdb..#compute_agentstatelog') is not null
  175. drop table #compute_agentstatelog
  176. if OBJECT_ID('tempdb..#t_stationcallrecord') is not null
  177. drop table #t_stationcallrecord
  178. if OBJECT_ID('tempdb..#SearchAgent') is not null
  179. drop table #SearchAgent
  180. select distinct Agent.Agent into #SearchAgent from Agent with(nolock) join Org_Agent with(nolock) on
  181. Agent.AgentID=Org_Agent.AgentID join Organization with(nolock) on Org_Agent.OrgID=Organization.OrgID
  182. and Org_Agent.OrgID in (@orgId)
  183. --某天每个小时的登录总时长
  184. select * into #compute_agentloginlog from agentloginlog
  185. where 1=1
  186. and (
  187. logintime >= @begintime and logintime < @endtime and logouttime >= @begintime and logouttime < @endtime
  188. or (logintime <= @begintime and (logouttime >= @endtime or LogoutTime is null))
  189. or (logintime <= @begintime and logouttime >= @begintime and logouttime < @endtime)
  190. or (logintime >= @begintime and logintime < @endtime and (logouttime > @endtime or LogoutTime is null))
  191. )
  192. and agentid in (select agent from #SearchAgent)
  193. set @ihour=1;
  194. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  195. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  196. from #compute_agentloginlog
  197. where
  198. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  199. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  200. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  201. from #compute_agentloginlog
  202. where
  203. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  204. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  205. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  206. from #compute_agentloginlog
  207. where
  208. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  209. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  210. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  211. from #compute_agentloginlog
  212. where
  213. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  214. set @logintime_hour00=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  215. set @ihour=@ihour+1;
  216. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  217. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  218. from #compute_agentloginlog
  219. where
  220. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  221. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  222. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  223. from #compute_agentloginlog
  224. where
  225. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  226. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  227. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  228. from #compute_agentloginlog
  229. where
  230. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  231. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  232. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  233. from #compute_agentloginlog
  234. where
  235. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  236. set @logintime_hour01=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  237. set @ihour=@ihour+1;
  238. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  239. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  240. from #compute_agentloginlog
  241. where
  242. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  243. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  244. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  245. from #compute_agentloginlog
  246. where
  247. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  248. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  249. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  250. from #compute_agentloginlog
  251. where
  252. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  253. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  254. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  255. from #compute_agentloginlog
  256. where
  257. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  258. set @logintime_hour02=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  259. set @ihour=@ihour+1;
  260. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  261. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  262. from #compute_agentloginlog
  263. where
  264. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  265. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  266. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  267. from #compute_agentloginlog
  268. where
  269. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  270. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  271. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  272. from #compute_agentloginlog
  273. where
  274. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  275. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  276. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  277. from #compute_agentloginlog
  278. where
  279. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  280. set @logintime_hour03=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  281. set @ihour=@ihour+1;
  282. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  283. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  284. from #compute_agentloginlog
  285. where
  286. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  287. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  288. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  289. from #compute_agentloginlog
  290. where
  291. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  292. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  293. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  294. from #compute_agentloginlog
  295. where
  296. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  297. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  298. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  299. from #compute_agentloginlog
  300. where
  301. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  302. set @logintime_hour04=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  303. set @ihour=@ihour+1;
  304. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  305. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  306. from #compute_agentloginlog
  307. where
  308. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  309. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  310. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  311. from #compute_agentloginlog
  312. where
  313. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  314. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  315. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  316. from #compute_agentloginlog
  317. where
  318. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  319. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  320. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  321. from #compute_agentloginlog
  322. where
  323. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  324. set @logintime_hour05=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  325. set @ihour=@ihour+1;
  326. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  327. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  328. from #compute_agentloginlog
  329. where
  330. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  331. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  332. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  333. from #compute_agentloginlog
  334. where
  335. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  336. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  337. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  338. from #compute_agentloginlog
  339. where
  340. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  341. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  342. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  343. from #compute_agentloginlog
  344. where
  345. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  346. set @logintime_hour06=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  347. set @ihour=@ihour+1;
  348. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  349. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  350. from #compute_agentloginlog
  351. where
  352. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  353. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  354. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  355. from #compute_agentloginlog
  356. where
  357. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  358. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  359. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  360. from #compute_agentloginlog
  361. where
  362. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  363. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  364. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  365. from #compute_agentloginlog
  366. where
  367. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  368. set @logintime_hour07=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  369. set @ihour=@ihour+1;
  370. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  371. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  372. from #compute_agentloginlog
  373. where
  374. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  375. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  376. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  377. from #compute_agentloginlog
  378. where
  379. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  380. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  381. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  382. from #compute_agentloginlog
  383. where
  384. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  385. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  386. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  387. from #compute_agentloginlog
  388. where
  389. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  390. set @logintime_hour08=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  391. set @ihour=@ihour+1;
  392. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  393. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  394. from #compute_agentloginlog
  395. where
  396. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  397. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  398. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  399. from #compute_agentloginlog
  400. where
  401. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  402. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  403. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  404. from #compute_agentloginlog
  405. where
  406. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  407. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  408. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  409. from #compute_agentloginlog
  410. where
  411. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  412. set @logintime_hour09=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  413. set @ihour=@ihour+1;
  414. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  415. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  416. from #compute_agentloginlog
  417. where
  418. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  419. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  420. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  421. from #compute_agentloginlog
  422. where
  423. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  424. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  425. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  426. from #compute_agentloginlog
  427. where
  428. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  429. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  430. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  431. from #compute_agentloginlog
  432. where
  433. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  434. set @logintime_hour10=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  435. set @ihour=@ihour+1;
  436. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  437. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  438. from #compute_agentloginlog
  439. where
  440. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  441. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  442. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  443. from #compute_agentloginlog
  444. where
  445. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  446. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  447. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  448. from #compute_agentloginlog
  449. where
  450. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  451. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  452. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  453. from #compute_agentloginlog
  454. where
  455. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  456. set @logintime_hour11=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  457. set @ihour=@ihour+1;
  458. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  459. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  460. from #compute_agentloginlog
  461. where
  462. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  463. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  464. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  465. from #compute_agentloginlog
  466. where
  467. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  468. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  469. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  470. from #compute_agentloginlog
  471. where
  472. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  473. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  474. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  475. from #compute_agentloginlog
  476. where
  477. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  478. set @logintime_hour12=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  479. set @ihour=@ihour+1;
  480. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  481. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  482. from #compute_agentloginlog
  483. where
  484. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  485. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  486. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  487. from #compute_agentloginlog
  488. where
  489. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  490. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  491. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  492. from #compute_agentloginlog
  493. where
  494. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  495. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  496. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  497. from #compute_agentloginlog
  498. where
  499. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  500. set @logintime_hour13=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  501. set @ihour=@ihour+1;
  502. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  503. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  504. from #compute_agentloginlog
  505. where
  506. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  507. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  508. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  509. from #compute_agentloginlog
  510. where
  511. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  512. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  513. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  514. from #compute_agentloginlog
  515. where
  516. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  517. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  518. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  519. from #compute_agentloginlog
  520. where
  521. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  522. set @logintime_hour14=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  523. set @ihour=@ihour+1;
  524. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  525. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  526. from #compute_agentloginlog
  527. where
  528. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  529. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  530. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  531. from #compute_agentloginlog
  532. where
  533. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  534. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  535. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  536. from #compute_agentloginlog
  537. where
  538. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  539. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  540. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  541. from #compute_agentloginlog
  542. where
  543. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  544. set @logintime_hour15=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  545. set @ihour=@ihour+1;
  546. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  547. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  548. from #compute_agentloginlog
  549. where
  550. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  551. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  552. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  553. from #compute_agentloginlog
  554. where
  555. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  556. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  557. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  558. from #compute_agentloginlog
  559. where
  560. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  561. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  562. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  563. from #compute_agentloginlog
  564. where
  565. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  566. set @logintime_hour16=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  567. set @ihour=@ihour+1;
  568. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  569. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  570. from #compute_agentloginlog
  571. where
  572. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  573. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  574. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  575. from #compute_agentloginlog
  576. where
  577. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  578. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  579. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  580. from #compute_agentloginlog
  581. where
  582. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  583. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  584. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  585. from #compute_agentloginlog
  586. where
  587. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  588. set @logintime_hour17=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  589. set @ihour=@ihour+1;
  590. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  591. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  592. from #compute_agentloginlog
  593. where
  594. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  595. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  596. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  597. from #compute_agentloginlog
  598. where
  599. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  600. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  601. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  602. from #compute_agentloginlog
  603. where
  604. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  605. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  606. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  607. from #compute_agentloginlog
  608. where
  609. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  610. set @logintime_hour18=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  611. set @ihour=@ihour+1;
  612. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  613. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  614. from #compute_agentloginlog
  615. where
  616. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  617. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  618. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  619. from #compute_agentloginlog
  620. where
  621. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  622. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  623. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  624. from #compute_agentloginlog
  625. where
  626. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  627. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  628. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  629. from #compute_agentloginlog
  630. where
  631. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  632. set @logintime_hour19=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  633. set @ihour=@ihour+1;
  634. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  635. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  636. from #compute_agentloginlog
  637. where
  638. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  639. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  640. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  641. from #compute_agentloginlog
  642. where
  643. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  644. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  645. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  646. from #compute_agentloginlog
  647. where
  648. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  649. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  650. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  651. from #compute_agentloginlog
  652. where
  653. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  654. set @logintime_hour20=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  655. set @ihour=@ihour+1;
  656. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  657. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  658. from #compute_agentloginlog
  659. where
  660. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  661. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  662. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  663. from #compute_agentloginlog
  664. where
  665. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  666. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  667. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  668. from #compute_agentloginlog
  669. where
  670. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  671. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  672. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  673. from #compute_agentloginlog
  674. where
  675. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  676. set @logintime_hour21=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  677. set @ihour=@ihour+1;
  678. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  679. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  680. from #compute_agentloginlog
  681. where
  682. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  683. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  684. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  685. from #compute_agentloginlog
  686. where
  687. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  688. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  689. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  690. from #compute_agentloginlog
  691. where
  692. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  693. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  694. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  695. from #compute_agentloginlog
  696. where
  697. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  698. set @logintime_hour22=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  699. set @ihour=@ihour+1;
  700. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  701. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  702. from #compute_agentloginlog
  703. where
  704. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  705. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  706. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  707. from #compute_agentloginlog
  708. where
  709. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  710. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  711. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  712. from #compute_agentloginlog
  713. where
  714. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  715. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  716. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  717. from #compute_agentloginlog
  718. where
  719. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  720. set @logintime_hour23=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  721. set @ihour=@ihour+1;
  722. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  723. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  724. from #compute_agentloginlog
  725. where
  726. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  727. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  728. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  729. from #compute_agentloginlog
  730. where
  731. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  732. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  733. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  734. from #compute_agentloginlog
  735. where
  736. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  737. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  738. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  739. from #compute_agentloginlog
  740. where
  741. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  742. set @logintime_hour24=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  743. set @ihour=@ihour+1;
  744. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  745. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  746. from #compute_agentloginlog
  747. where
  748. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  749. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  750. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  751. from #compute_agentloginlog
  752. where
  753. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  754. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  755. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  756. from #compute_agentloginlog
  757. where
  758. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  759. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  760. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  761. from #compute_agentloginlog
  762. where
  763. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  764. set @logintime_hour25=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  765. set @ihour=@ihour+1;
  766. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  767. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  768. from #compute_agentloginlog
  769. where
  770. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  771. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  772. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  773. from #compute_agentloginlog
  774. where
  775. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  776. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  777. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  778. from #compute_agentloginlog
  779. where
  780. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  781. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  782. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  783. from #compute_agentloginlog
  784. where
  785. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  786. set @logintime_hour26=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  787. set @ihour=@ihour+1;
  788. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  789. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  790. from #compute_agentloginlog
  791. where
  792. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  793. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  794. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  795. from #compute_agentloginlog
  796. where
  797. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  798. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  799. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  800. from #compute_agentloginlog
  801. where
  802. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  803. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  804. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  805. from #compute_agentloginlog
  806. where
  807. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  808. set @logintime_hour27=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  809. set @ihour=@ihour+1;
  810. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  811. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  812. from #compute_agentloginlog
  813. where
  814. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  815. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  816. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  817. from #compute_agentloginlog
  818. where
  819. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  820. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  821. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  822. from #compute_agentloginlog
  823. where
  824. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  825. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  826. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  827. from #compute_agentloginlog
  828. where
  829. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  830. set @logintime_hour28=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  831. set @ihour=@ihour+1;
  832. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  833. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  834. from #compute_agentloginlog
  835. where
  836. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  837. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  838. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  839. from #compute_agentloginlog
  840. where
  841. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  842. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  843. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  844. from #compute_agentloginlog
  845. where
  846. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  847. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  848. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  849. from #compute_agentloginlog
  850. where
  851. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  852. set @logintime_hour29=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  853. set @ihour=@ihour+1;
  854. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  855. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  856. from #compute_agentloginlog
  857. where
  858. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  859. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  860. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  861. from #compute_agentloginlog
  862. where
  863. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  864. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  865. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  866. from #compute_agentloginlog
  867. where
  868. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  869. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  870. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  871. from #compute_agentloginlog
  872. where
  873. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  874. set @logintime_hour30=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  875. set @ihour=@ihour+1;
  876. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  877. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  878. from #compute_agentloginlog
  879. where
  880. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  881. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  882. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  883. from #compute_agentloginlog
  884. where
  885. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  886. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  887. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  888. from #compute_agentloginlog
  889. where
  890. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  891. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  892. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  893. from #compute_agentloginlog
  894. where
  895. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  896. set @logintime_hour31=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  897. set @ihour=@ihour+1;
  898. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  899. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  900. from #compute_agentloginlog
  901. where
  902. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  903. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  904. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  905. from #compute_agentloginlog
  906. where
  907. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  908. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  909. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  910. from #compute_agentloginlog
  911. where
  912. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  913. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  914. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  915. from #compute_agentloginlog
  916. where
  917. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  918. set @logintime_hour32=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  919. set @ihour=@ihour+1;
  920. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  921. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  922. from #compute_agentloginlog
  923. where
  924. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  925. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  926. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  927. from #compute_agentloginlog
  928. where
  929. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  930. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  931. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  932. from #compute_agentloginlog
  933. where
  934. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  935. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  936. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  937. from #compute_agentloginlog
  938. where
  939. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  940. set @logintime_hour33=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  941. set @ihour=@ihour+1;
  942. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  943. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  944. from #compute_agentloginlog
  945. where
  946. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  947. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  948. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  949. from #compute_agentloginlog
  950. where
  951. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  952. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  953. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  954. from #compute_agentloginlog
  955. where
  956. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  957. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  958. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  959. from #compute_agentloginlog
  960. where
  961. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  962. set @logintime_hour34=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  963. set @ihour=@ihour+1;
  964. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  965. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  966. from #compute_agentloginlog
  967. where
  968. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  969. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  970. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  971. from #compute_agentloginlog
  972. where
  973. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  974. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  975. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  976. from #compute_agentloginlog
  977. where
  978. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  979. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  980. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  981. from #compute_agentloginlog
  982. where
  983. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  984. set @logintime_hour35=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  985. set @ihour=@ihour+1;
  986. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  987. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  988. from #compute_agentloginlog
  989. where
  990. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  991. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  992. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  993. from #compute_agentloginlog
  994. where
  995. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  996. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  997. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  998. from #compute_agentloginlog
  999. where
  1000. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1001. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  1002. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  1003. from #compute_agentloginlog
  1004. where
  1005. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1006. set @logintime_hour36=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  1007. set @ihour=@ihour+1;
  1008. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  1009. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  1010. from #compute_agentloginlog
  1011. where
  1012. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1013. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  1014. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  1015. from #compute_agentloginlog
  1016. where
  1017. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1018. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  1019. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  1020. from #compute_agentloginlog
  1021. where
  1022. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1023. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  1024. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  1025. from #compute_agentloginlog
  1026. where
  1027. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1028. set @logintime_hour37=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  1029. set @ihour=@ihour+1;
  1030. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  1031. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  1032. from #compute_agentloginlog
  1033. where
  1034. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1035. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  1036. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  1037. from #compute_agentloginlog
  1038. where
  1039. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1040. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  1041. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  1042. from #compute_agentloginlog
  1043. where
  1044. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1045. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  1046. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  1047. from #compute_agentloginlog
  1048. where
  1049. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1050. set @logintime_hour38=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  1051. set @ihour=@ihour+1;
  1052. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  1053. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  1054. from #compute_agentloginlog
  1055. where
  1056. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1057. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  1058. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  1059. from #compute_agentloginlog
  1060. where
  1061. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1062. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  1063. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  1064. from #compute_agentloginlog
  1065. where
  1066. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1067. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  1068. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  1069. from #compute_agentloginlog
  1070. where
  1071. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1072. set @logintime_hour39=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  1073. set @ihour=@ihour+1;
  1074. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  1075. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  1076. from #compute_agentloginlog
  1077. where
  1078. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1079. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  1080. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  1081. from #compute_agentloginlog
  1082. where
  1083. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1084. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  1085. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  1086. from #compute_agentloginlog
  1087. where
  1088. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1089. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  1090. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  1091. from #compute_agentloginlog
  1092. where
  1093. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1094. set @logintime_hour40=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  1095. set @ihour=@ihour+1;
  1096. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  1097. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  1098. from #compute_agentloginlog
  1099. where
  1100. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1101. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  1102. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  1103. from #compute_agentloginlog
  1104. where
  1105. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1106. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  1107. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  1108. from #compute_agentloginlog
  1109. where
  1110. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1111. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  1112. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  1113. from #compute_agentloginlog
  1114. where
  1115. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1116. set @logintime_hour41=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  1117. set @ihour=@ihour+1;
  1118. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  1119. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  1120. from #compute_agentloginlog
  1121. where
  1122. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1123. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  1124. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  1125. from #compute_agentloginlog
  1126. where
  1127. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1128. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  1129. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  1130. from #compute_agentloginlog
  1131. where
  1132. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1133. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  1134. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  1135. from #compute_agentloginlog
  1136. where
  1137. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1138. set @logintime_hour42=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  1139. set @ihour=@ihour+1;
  1140. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  1141. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  1142. from #compute_agentloginlog
  1143. where
  1144. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1145. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  1146. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  1147. from #compute_agentloginlog
  1148. where
  1149. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1150. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  1151. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  1152. from #compute_agentloginlog
  1153. where
  1154. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1155. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  1156. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  1157. from #compute_agentloginlog
  1158. where
  1159. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1160. set @logintime_hour43=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  1161. set @ihour=@ihour+1;
  1162. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  1163. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  1164. from #compute_agentloginlog
  1165. where
  1166. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1167. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  1168. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  1169. from #compute_agentloginlog
  1170. where
  1171. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1172. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  1173. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  1174. from #compute_agentloginlog
  1175. where
  1176. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1177. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  1178. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  1179. from #compute_agentloginlog
  1180. where
  1181. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1182. set @logintime_hour44=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  1183. set @ihour=@ihour+1;
  1184. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  1185. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  1186. from #compute_agentloginlog
  1187. where
  1188. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1189. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  1190. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  1191. from #compute_agentloginlog
  1192. where
  1193. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1194. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  1195. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  1196. from #compute_agentloginlog
  1197. where
  1198. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1199. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  1200. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  1201. from #compute_agentloginlog
  1202. where
  1203. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1204. set @logintime_hour45=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  1205. set @ihour=@ihour+1;
  1206. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  1207. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  1208. from #compute_agentloginlog
  1209. where
  1210. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1211. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  1212. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  1213. from #compute_agentloginlog
  1214. where
  1215. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1216. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  1217. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  1218. from #compute_agentloginlog
  1219. where
  1220. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1221. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  1222. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  1223. from #compute_agentloginlog
  1224. where
  1225. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1226. set @logintime_hour46=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  1227. set @ihour=@ihour+1;
  1228. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  1229. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  1230. from #compute_agentloginlog
  1231. where
  1232. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1233. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  1234. select @i_stafftime2=isnull(sum(@ihour*1800),0)
  1235. from #compute_agentloginlog
  1236. where
  1237. logintime <= @begintime and (logouttime >= dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1238. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  1239. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  1240. from #compute_agentloginlog
  1241. where
  1242. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(MINUTE,@ihour*30,@begintime)
  1243. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  1244. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0)
  1245. from #compute_agentloginlog
  1246. where
  1247. logintime >= @begintime and logintime < dateadd(MINUTE,@ihour*30,@begintime) and (logouttime > dateadd(MINUTE,@ihour*30,@begintime) or LogoutTime is null)
  1248. set @logintime_hour47=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  1249. --每小时总的话后总时长
  1250. select * into #compute_agentstatelog from agentstatelog
  1251. where 1=1 and state=2
  1252. and (
  1253. (begintime >= @begintime and begintime < @endtime and endtime >= @begintime and endtime < @endtime )
  1254. or (begintime <= @begintime and (Endtime >= @endtime or Endtime is null))
  1255. or (begintime < @begintime and endtime >= @begintime and endtime < @endtime)
  1256. or (begintime >= @begintime and begintime < @endtime and (Endtime > @endtime or Endtime is null))
  1257. )
  1258. and agentid in (select Agent from #SearchAgent)
  1259. set @ihour=1;
  1260. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1261. where
  1262. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1263. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1264. where
  1265. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1266. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1267. where
  1268. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1269. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1270. where
  1271. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1272. set @acwtime_hour00=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1273. set @ihour=@ihour+1;
  1274. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1275. where
  1276. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1277. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1278. where
  1279. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1280. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1281. where
  1282. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1283. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1284. where
  1285. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1286. set @acwtime_hour01=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1287. set @ihour=@ihour+1;
  1288. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1289. where
  1290. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1291. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1292. where
  1293. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1294. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1295. where
  1296. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1297. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1298. where
  1299. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1300. set @acwtime_hour02=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1301. set @ihour=@ihour+1;
  1302. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1303. where
  1304. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1305. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1306. where
  1307. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1308. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1309. where
  1310. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1311. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1312. where
  1313. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1314. set @acwtime_hour03=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1315. set @ihour=@ihour+1;
  1316. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1317. where
  1318. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1319. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1320. where
  1321. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1322. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1323. where
  1324. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1325. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1326. where
  1327. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1328. set @acwtime_hour04=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1329. set @ihour=@ihour+1;
  1330. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1331. where
  1332. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1333. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1334. where
  1335. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1336. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1337. where
  1338. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1339. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1340. where
  1341. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1342. set @acwtime_hour05=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1343. set @ihour=@ihour+1;
  1344. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1345. where
  1346. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1347. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1348. where
  1349. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1350. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1351. where
  1352. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1353. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1354. where
  1355. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1356. set @acwtime_hour06=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1357. set @ihour=@ihour+1;
  1358. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1359. where
  1360. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1361. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1362. where
  1363. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1364. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1365. where
  1366. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1367. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1368. where
  1369. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1370. set @acwtime_hour07=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1371. set @ihour=@ihour+1;
  1372. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1373. where
  1374. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1375. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1376. where
  1377. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1378. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1379. where
  1380. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1381. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1382. where
  1383. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1384. set @acwtime_hour08=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1385. set @ihour=@ihour+1;
  1386. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1387. where
  1388. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1389. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1390. where
  1391. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1392. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1393. where
  1394. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1395. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1396. where
  1397. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1398. set @acwtime_hour09=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1399. set @ihour=@ihour+1;
  1400. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1401. where
  1402. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1403. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1404. where
  1405. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1406. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1407. where
  1408. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1409. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1410. where
  1411. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1412. set @acwtime_hour10=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1413. set @ihour=@ihour+1;
  1414. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1415. where
  1416. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1417. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1418. where
  1419. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1420. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1421. where
  1422. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1423. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1424. where
  1425. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1426. set @acwtime_hour11=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1427. set @ihour=@ihour+1;
  1428. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1429. where
  1430. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1431. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1432. where
  1433. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1434. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1435. where
  1436. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1437. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1438. where
  1439. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1440. set @acwtime_hour12=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1441. set @ihour=@ihour+1;
  1442. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1443. where
  1444. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1445. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1446. where
  1447. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1448. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1449. where
  1450. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1451. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1452. where
  1453. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1454. set @acwtime_hour13=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1455. set @ihour=@ihour+1;
  1456. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1457. where
  1458. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1459. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1460. where
  1461. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1462. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1463. where
  1464. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1465. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1466. where
  1467. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1468. set @acwtime_hour14=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1469. set @ihour=@ihour+1;
  1470. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1471. where
  1472. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1473. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1474. where
  1475. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1476. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1477. where
  1478. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1479. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1480. where
  1481. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1482. set @acwtime_hour15=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1483. set @ihour=@ihour+1;
  1484. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1485. where
  1486. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1487. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1488. where
  1489. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1490. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1491. where
  1492. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1493. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1494. where
  1495. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1496. set @acwtime_hour16=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1497. set @ihour=@ihour+1;
  1498. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1499. where
  1500. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1501. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1502. where
  1503. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1504. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1505. where
  1506. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1507. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1508. where
  1509. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1510. set @acwtime_hour17=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1511. set @ihour=@ihour+1;
  1512. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1513. where
  1514. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1515. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1516. where
  1517. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1518. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1519. where
  1520. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1521. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1522. where
  1523. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1524. set @acwtime_hour18=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1525. set @ihour=@ihour+1;
  1526. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1527. where
  1528. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1529. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1530. where
  1531. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1532. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1533. where
  1534. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1535. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1536. where
  1537. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1538. set @acwtime_hour19=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1539. set @ihour=@ihour+1;
  1540. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1541. where
  1542. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1543. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1544. where
  1545. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1546. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1547. where
  1548. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1549. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1550. where
  1551. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1552. set @acwtime_hour20=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1553. set @ihour=@ihour+1;
  1554. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1555. where
  1556. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1557. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1558. where
  1559. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1560. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1561. where
  1562. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1563. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1564. where
  1565. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1566. set @acwtime_hour21=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1567. set @ihour=@ihour+1;
  1568. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1569. where
  1570. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1571. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1572. where
  1573. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1574. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1575. where
  1576. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1577. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1578. where
  1579. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1580. set @acwtime_hour22=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1581. set @ihour=@ihour+1;
  1582. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1583. where
  1584. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1585. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1586. where
  1587. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1588. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1589. where
  1590. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1591. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1592. where
  1593. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1594. set @acwtime_hour23=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1595. set @ihour=@ihour+1;
  1596. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1597. where
  1598. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1599. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1600. where
  1601. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1602. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1603. where
  1604. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1605. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1606. where
  1607. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1608. set @acwtime_hour24=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1609. set @ihour=@ihour+1;
  1610. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1611. where
  1612. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1613. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1614. where
  1615. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1616. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1617. where
  1618. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1619. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1620. where
  1621. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1622. set @acwtime_hour25=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1623. set @ihour=@ihour+1;
  1624. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1625. where
  1626. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1627. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1628. where
  1629. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1630. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1631. where
  1632. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1633. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1634. where
  1635. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1636. set @acwtime_hour26=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1637. set @ihour=@ihour+1;
  1638. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1639. where
  1640. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1641. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1642. where
  1643. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1644. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1645. where
  1646. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1647. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1648. where
  1649. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1650. set @acwtime_hour27=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1651. set @ihour=@ihour+1;
  1652. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1653. where
  1654. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1655. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1656. where
  1657. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1658. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1659. where
  1660. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1661. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1662. where
  1663. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1664. set @acwtime_hour28=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1665. set @ihour=@ihour+1;
  1666. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1667. where
  1668. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1669. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1670. where
  1671. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1672. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1673. where
  1674. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1675. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1676. where
  1677. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1678. set @acwtime_hour29=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1679. set @ihour=@ihour+1;
  1680. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1681. where
  1682. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1683. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1684. where
  1685. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1686. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1687. where
  1688. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1689. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1690. where
  1691. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1692. set @acwtime_hour30=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1693. set @ihour=@ihour+1;
  1694. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1695. where
  1696. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1697. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1698. where
  1699. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1700. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1701. where
  1702. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1703. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1704. where
  1705. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1706. set @acwtime_hour31=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1707. set @ihour=@ihour+1;
  1708. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1709. where
  1710. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1711. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1712. where
  1713. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1714. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1715. where
  1716. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1717. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1718. where
  1719. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1720. set @acwtime_hour32=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1721. set @ihour=@ihour+1;
  1722. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1723. where
  1724. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1725. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1726. where
  1727. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1728. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1729. where
  1730. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1731. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1732. where
  1733. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1734. set @acwtime_hour33=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1735. set @ihour=@ihour+1;
  1736. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1737. where
  1738. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1739. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1740. where
  1741. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1742. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1743. where
  1744. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1745. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1746. where
  1747. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1748. set @acwtime_hour34=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1749. set @ihour=@ihour+1;
  1750. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1751. where
  1752. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1753. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1754. where
  1755. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1756. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1757. where
  1758. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1759. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1760. where
  1761. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1762. set @acwtime_hour35=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1763. set @ihour=@ihour+1;
  1764. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1765. where
  1766. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1767. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1768. where
  1769. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1770. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1771. where
  1772. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1773. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1774. where
  1775. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1776. set @acwtime_hour36=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1777. set @ihour=@ihour+1;
  1778. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1779. where
  1780. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1781. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1782. where
  1783. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1784. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1785. where
  1786. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1787. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1788. where
  1789. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1790. set @acwtime_hour37=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1791. set @ihour=@ihour+1;
  1792. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1793. where
  1794. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1795. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1796. where
  1797. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1798. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1799. where
  1800. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1801. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1802. where
  1803. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1804. set @acwtime_hour38=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1805. set @ihour=@ihour+1;
  1806. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1807. where
  1808. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1809. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1810. where
  1811. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1812. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1813. where
  1814. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1815. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1816. where
  1817. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1818. set @acwtime_hour39=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1819. set @ihour=@ihour+1;
  1820. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1821. where
  1822. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1823. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1824. where
  1825. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1826. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1827. where
  1828. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1829. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1830. where
  1831. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1832. set @acwtime_hour40=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1833. set @ihour=@ihour+1;
  1834. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1835. where
  1836. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1837. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1838. where
  1839. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1840. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1841. where
  1842. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1843. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1844. where
  1845. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1846. set @acwtime_hour41=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1847. set @ihour=@ihour+1;
  1848. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1849. where
  1850. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1851. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1852. where
  1853. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1854. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1855. where
  1856. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1857. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1858. where
  1859. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1860. set @acwtime_hour42=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1861. set @ihour=@ihour+1;
  1862. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1863. where
  1864. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1865. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1866. where
  1867. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1868. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1869. where
  1870. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1871. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1872. where
  1873. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1874. set @acwtime_hour43=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1875. set @ihour=@ihour+1;
  1876. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1877. where
  1878. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1879. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1880. where
  1881. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1882. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1883. where
  1884. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1885. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1886. where
  1887. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1888. set @acwtime_hour44=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1889. set @ihour=@ihour+1;
  1890. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1891. where
  1892. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1893. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1894. where
  1895. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1896. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1897. where
  1898. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1899. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1900. where
  1901. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1902. set @acwtime_hour45=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1903. set @ihour=@ihour+1;
  1904. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1905. where
  1906. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1907. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1908. where
  1909. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1910. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1911. where
  1912. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1913. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1914. where
  1915. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1916. set @acwtime_hour46=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1917. set @ihour=@ihour+1;
  1918. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  1919. where
  1920. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1921. select @i_acwtime2=isnull(sum(@ihour*1800),0) from #compute_agentstatelog
  1922. where
  1923. begintime <= @begintime and (Endtime >= dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1924. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  1925. where
  1926. begintime < @begintime and endtime >= @begintime and endtime < dateadd(MINUTE,@ihour*30,@begintime)
  1927. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(MINUTE,@ihour*30,@begintime)),0)),0) from #compute_agentstatelog
  1928. where
  1929. begintime >= @begintime and begintime < dateadd(MINUTE,@ihour*30,@begintime) and (Endtime > dateadd(MINUTE,@ihour*30,@begintime) or Endtime is null)
  1930. set @acwtime_hour47=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1931. --每小时总的通话总时长
  1932. select * into #t_stationcallrecord
  1933. from stationcallrecord with(nolock)
  1934. where 1=1
  1935. and (End_Time >=@begintime and End_Time <@endtime)
  1936. --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')
  1937. and calldirect=1
  1938. and split != ''
  1939. and AgentID in
  1940. (
  1941. select Agent from #SearchAgent
  1942. );
  1943. set @ihour=1;
  1944. select @acdtime_hour00=
  1945. isnull(sum(talk_dur),0)
  1946. from #t_stationcallrecord
  1947. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1948. ;
  1949. set @ihour=@ihour+1;
  1950. select @acdtime_hour01=
  1951. isnull(sum(talk_dur),0)
  1952. from #t_stationcallrecord
  1953. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1954. ;
  1955. set @ihour=@ihour+1;
  1956. select @acdtime_hour02=
  1957. isnull(sum(talk_dur),0)
  1958. from #t_stationcallrecord
  1959. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1960. ;
  1961. set @ihour=@ihour+1;
  1962. select @acdtime_hour03=
  1963. isnull(sum(talk_dur),0)
  1964. from #t_stationcallrecord
  1965. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1966. ;
  1967. set @ihour=@ihour+1;
  1968. select @acdtime_hour04=
  1969. isnull(sum(talk_dur),0)
  1970. from #t_stationcallrecord
  1971. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1972. ;
  1973. set @ihour=@ihour+1;
  1974. select @acdtime_hour05=
  1975. isnull(sum(talk_dur),0)
  1976. from #t_stationcallrecord
  1977. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1978. ;
  1979. set @ihour=@ihour+1;
  1980. select @acdtime_hour06=
  1981. isnull(sum(talk_dur),0)
  1982. from #t_stationcallrecord
  1983. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1984. ;
  1985. set @ihour=@ihour+1;
  1986. select @acdtime_hour07=
  1987. isnull(sum(talk_dur),0)
  1988. from #t_stationcallrecord
  1989. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1990. ;
  1991. set @ihour=@ihour+1;
  1992. select @acdtime_hour08=
  1993. isnull(sum(talk_dur),0)
  1994. from #t_stationcallrecord
  1995. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  1996. ;
  1997. set @ihour=@ihour+1;
  1998. select @acdtime_hour09=
  1999. isnull(sum(talk_dur),0)
  2000. from #t_stationcallrecord
  2001. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2002. ;
  2003. set @ihour=@ihour+1;
  2004. select @acdtime_hour10=
  2005. isnull(sum(talk_dur),0)
  2006. from #t_stationcallrecord
  2007. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2008. ;
  2009. set @ihour=@ihour+1;
  2010. select @acdtime_hour11=
  2011. isnull(sum(talk_dur),0)
  2012. from #t_stationcallrecord
  2013. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2014. ;
  2015. set @ihour=@ihour+1;
  2016. select @acdtime_hour12=
  2017. isnull(sum(talk_dur),0)
  2018. from #t_stationcallrecord
  2019. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2020. ;
  2021. set @ihour=@ihour+1;
  2022. select @acdtime_hour13=
  2023. isnull(sum(talk_dur),0)
  2024. from #t_stationcallrecord
  2025. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2026. ;
  2027. set @ihour=@ihour+1;
  2028. select @acdtime_hour14=
  2029. isnull(sum(talk_dur),0)
  2030. from #t_stationcallrecord
  2031. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2032. ;
  2033. set @ihour=@ihour+1;
  2034. select @acdtime_hour15=
  2035. isnull(sum(talk_dur),0)
  2036. from #t_stationcallrecord
  2037. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2038. ;
  2039. set @ihour=@ihour+1;
  2040. select @acdtime_hour16=
  2041. isnull(sum(talk_dur),0)
  2042. from #t_stationcallrecord
  2043. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2044. ;
  2045. set @ihour=@ihour+1;
  2046. select @acdtime_hour17=
  2047. isnull(sum(talk_dur),0)
  2048. from #t_stationcallrecord
  2049. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2050. ;
  2051. set @ihour=@ihour+1;
  2052. select @acdtime_hour18=
  2053. isnull(sum(talk_dur),0)
  2054. from #t_stationcallrecord
  2055. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2056. ;
  2057. set @ihour=@ihour+1;
  2058. select @acdtime_hour19=
  2059. isnull(sum(talk_dur),0)
  2060. from #t_stationcallrecord
  2061. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2062. ;
  2063. set @ihour=@ihour+1;
  2064. select @acdtime_hour20=
  2065. isnull(sum(talk_dur),0)
  2066. from #t_stationcallrecord
  2067. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2068. ;
  2069. set @ihour=@ihour+1;
  2070. select @acdtime_hour21=
  2071. isnull(sum(talk_dur),0)
  2072. from #t_stationcallrecord
  2073. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2074. ;
  2075. set @ihour=@ihour+1;
  2076. select @acdtime_hour22=
  2077. isnull(sum(talk_dur),0)
  2078. from #t_stationcallrecord
  2079. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2080. ;
  2081. set @ihour=@ihour+1;
  2082. select @acdtime_hour23=
  2083. isnull(sum(talk_dur),0)
  2084. from #t_stationcallrecord
  2085. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2086. ;
  2087. set @ihour=@ihour+1;
  2088. select @acdtime_hour24=
  2089. isnull(sum(talk_dur),0)
  2090. from #t_stationcallrecord
  2091. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2092. ;
  2093. set @ihour=@ihour+1;
  2094. select @acdtime_hour25=
  2095. isnull(sum(talk_dur),0)
  2096. from #t_stationcallrecord
  2097. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2098. ;
  2099. set @ihour=@ihour+1;
  2100. select @acdtime_hour26=
  2101. isnull(sum(talk_dur),0)
  2102. from #t_stationcallrecord
  2103. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2104. ;
  2105. set @ihour=@ihour+1;
  2106. select @acdtime_hour27=
  2107. isnull(sum(talk_dur),0)
  2108. from #t_stationcallrecord
  2109. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2110. ;
  2111. set @ihour=@ihour+1;
  2112. select @acdtime_hour28=
  2113. isnull(sum(talk_dur),0)
  2114. from #t_stationcallrecord
  2115. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2116. ;
  2117. set @ihour=@ihour+1;
  2118. select @acdtime_hour29=
  2119. isnull(sum(talk_dur),0)
  2120. from #t_stationcallrecord
  2121. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2122. ;
  2123. set @ihour=@ihour+1;
  2124. select @acdtime_hour30=
  2125. isnull(sum(talk_dur),0)
  2126. from #t_stationcallrecord
  2127. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2128. ;
  2129. set @ihour=@ihour+1;
  2130. select @acdtime_hour31=
  2131. isnull(sum(talk_dur),0)
  2132. from #t_stationcallrecord
  2133. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2134. ;
  2135. set @ihour=@ihour+1;
  2136. select @acdtime_hour32=
  2137. isnull(sum(talk_dur),0)
  2138. from #t_stationcallrecord
  2139. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2140. ;
  2141. set @ihour=@ihour+1;
  2142. select @acdtime_hour33=
  2143. isnull(sum(talk_dur),0)
  2144. from #t_stationcallrecord
  2145. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2146. ;
  2147. set @ihour=@ihour+1;
  2148. select @acdtime_hour34=
  2149. isnull(sum(talk_dur),0)
  2150. from #t_stationcallrecord
  2151. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2152. ;
  2153. set @ihour=@ihour+1;
  2154. select @acdtime_hour35=
  2155. isnull(sum(talk_dur),0)
  2156. from #t_stationcallrecord
  2157. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2158. ;
  2159. set @ihour=@ihour+1;
  2160. select @acdtime_hour36=
  2161. isnull(sum(talk_dur),0)
  2162. from #t_stationcallrecord
  2163. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2164. ;
  2165. set @ihour=@ihour+1;
  2166. select @acdtime_hour37=
  2167. isnull(sum(talk_dur),0)
  2168. from #t_stationcallrecord
  2169. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2170. ;
  2171. set @ihour=@ihour+1;
  2172. select @acdtime_hour38=
  2173. isnull(sum(talk_dur),0)
  2174. from #t_stationcallrecord
  2175. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2176. ;
  2177. set @ihour=@ihour+1;
  2178. select @acdtime_hour39=
  2179. isnull(sum(talk_dur),0)
  2180. from #t_stationcallrecord
  2181. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2182. ;
  2183. set @ihour=@ihour+1;
  2184. select @acdtime_hour40=
  2185. isnull(sum(talk_dur),0)
  2186. from #t_stationcallrecord
  2187. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2188. ;
  2189. set @ihour=@ihour+1;
  2190. select @acdtime_hour41=
  2191. isnull(sum(talk_dur),0)
  2192. from #t_stationcallrecord
  2193. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2194. ;
  2195. set @ihour=@ihour+1;
  2196. select @acdtime_hour42=
  2197. isnull(sum(talk_dur),0)
  2198. from #t_stationcallrecord
  2199. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2200. ;
  2201. set @ihour=@ihour+1;
  2202. select @acdtime_hour43=
  2203. isnull(sum(talk_dur),0)
  2204. from #t_stationcallrecord
  2205. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2206. ;
  2207. set @ihour=@ihour+1;
  2208. select @acdtime_hour44=
  2209. isnull(sum(talk_dur),0)
  2210. from #t_stationcallrecord
  2211. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2212. ;
  2213. set @ihour=@ihour+1;
  2214. select @acdtime_hour45=
  2215. isnull(sum(talk_dur),0)
  2216. from #t_stationcallrecord
  2217. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2218. ;
  2219. set @ihour=@ihour+1;
  2220. select @acdtime_hour46=
  2221. isnull(sum(talk_dur),0)
  2222. from #t_stationcallrecord
  2223. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2224. ;
  2225. set @ihour=@ihour+1;
  2226. select @acdtime_hour47=
  2227. isnull(sum(talk_dur),0)
  2228. from #t_stationcallrecord
  2229. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(MINUTE,@ihour*30,@begintime))
  2230. ;
  2231. select case when @logintime_hour00=0 then 0 else round(cast( (@acdtime_hour00+@acwtime_hour00) as float)/@logintime_hour00,4) end as UtilizationRate00,
  2232. case when @logintime_hour01=0 then 0 else round(cast( (@acdtime_hour01+@acwtime_hour01) as float)/@logintime_hour01,4) end as UtilizationRate01,
  2233. case when @logintime_hour02=0 then 0 else round(cast( (@acdtime_hour02+@acwtime_hour02) as float)/@logintime_hour02,4) end as UtilizationRate02,
  2234. case when @logintime_hour03=0 then 0 else round(cast( (@acdtime_hour03+@acwtime_hour03) as float)/@logintime_hour03,4) end as UtilizationRate03,
  2235. case when @logintime_hour04=0 then 0 else round(cast( (@acdtime_hour04+@acwtime_hour04) as float)/@logintime_hour04,4) end as UtilizationRate04,
  2236. case when @logintime_hour05=0 then 0 else round(cast( (@acdtime_hour05+@acwtime_hour05) as float)/@logintime_hour05,4) end as UtilizationRate05,
  2237. case when @logintime_hour06=0 then 0 else round(cast( (@acdtime_hour06+@acwtime_hour06) as float)/@logintime_hour06,4) end as UtilizationRate06,
  2238. case when @logintime_hour07=0 then 0 else round(cast( (@acdtime_hour07+@acwtime_hour07) as float)/@logintime_hour07,4) end as UtilizationRate07,
  2239. case when @logintime_hour08=0 then 0 else round(cast( (@acdtime_hour08+@acwtime_hour08) as float)/@logintime_hour08,4) end as UtilizationRate08,
  2240. case when @logintime_hour09=0 then 0 else round(cast( (@acdtime_hour09+@acwtime_hour09) as float)/@logintime_hour09,4) end as UtilizationRate09,
  2241. case when @logintime_hour10=0 then 0 else round(cast( (@acdtime_hour10+@acwtime_hour10) as float)/@logintime_hour10,4) end as UtilizationRate10,
  2242. case when @logintime_hour11=0 then 0 else round(cast( (@acdtime_hour11+@acwtime_hour11) as float)/@logintime_hour11,4) end as UtilizationRate11,
  2243. case when @logintime_hour12=0 then 0 else round(cast( (@acdtime_hour12+@acwtime_hour12) as float)/@logintime_hour12,4) end as UtilizationRate12,
  2244. case when @logintime_hour13=0 then 0 else round(cast( (@acdtime_hour13+@acwtime_hour13) as float)/@logintime_hour13,4) end as UtilizationRate13,
  2245. case when @logintime_hour14=0 then 0 else round(cast( (@acdtime_hour14+@acwtime_hour14) as float)/@logintime_hour14,4) end as UtilizationRate14,
  2246. case when @logintime_hour15=0 then 0 else round(cast( (@acdtime_hour15+@acwtime_hour15) as float)/@logintime_hour15,4) end as UtilizationRate15,
  2247. case when @logintime_hour16=0 then 0 else round(cast( (@acdtime_hour16+@acwtime_hour16) as float)/@logintime_hour16,4) end as UtilizationRate16,
  2248. case when @logintime_hour17=0 then 0 else round(cast( (@acdtime_hour17+@acwtime_hour17) as float)/@logintime_hour17,4) end as UtilizationRate17,
  2249. case when @logintime_hour18=0 then 0 else round(cast( (@acdtime_hour18+@acwtime_hour18) as float)/@logintime_hour18,4) end as UtilizationRate18,
  2250. case when @logintime_hour19=0 then 0 else round(cast( (@acdtime_hour19+@acwtime_hour19) as float)/@logintime_hour19,4) end as UtilizationRate19,
  2251. case when @logintime_hour20=0 then 0 else round(cast( (@acdtime_hour20+@acwtime_hour20) as float)/@logintime_hour20,4) end as UtilizationRate20,
  2252. case when @logintime_hour21=0 then 0 else round(cast( (@acdtime_hour21+@acwtime_hour21) as float)/@logintime_hour21,4) end as UtilizationRate21,
  2253. case when @logintime_hour22=0 then 0 else round(cast( (@acdtime_hour22+@acwtime_hour22) as float)/@logintime_hour22,4) end as UtilizationRate22,
  2254. case when @logintime_hour23=0 then 0 else round(cast( (@acdtime_hour23+@acwtime_hour23) as float)/@logintime_hour23,4) end as UtilizationRate23,
  2255. case when @logintime_hour24=0 then 0 else round(cast( (@acdtime_hour24+@acwtime_hour24) as float)/@logintime_hour24,4) end as UtilizationRate24,
  2256. case when @logintime_hour25=0 then 0 else round(cast( (@acdtime_hour25+@acwtime_hour25) as float)/@logintime_hour25,4) end as UtilizationRate25,
  2257. case when @logintime_hour26=0 then 0 else round(cast( (@acdtime_hour26+@acwtime_hour26) as float)/@logintime_hour26,4) end as UtilizationRate26,
  2258. case when @logintime_hour27=0 then 0 else round(cast( (@acdtime_hour27+@acwtime_hour27) as float)/@logintime_hour27,4) end as UtilizationRate27,
  2259. case when @logintime_hour28=0 then 0 else round(cast( (@acdtime_hour28+@acwtime_hour28) as float)/@logintime_hour28,4) end as UtilizationRate28,
  2260. case when @logintime_hour29=0 then 0 else round(cast( (@acdtime_hour29+@acwtime_hour29) as float)/@logintime_hour29,4) end as UtilizationRate29,
  2261. case when @logintime_hour30=0 then 0 else round(cast( (@acdtime_hour30+@acwtime_hour30) as float)/@logintime_hour30,4) end as UtilizationRate30,
  2262. case when @logintime_hour31=0 then 0 else round(cast( (@acdtime_hour31+@acwtime_hour31) as float)/@logintime_hour31,4) end as UtilizationRate31,
  2263. case when @logintime_hour32=0 then 0 else round(cast( (@acdtime_hour32+@acwtime_hour32) as float)/@logintime_hour32,4) end as UtilizationRate32,
  2264. case when @logintime_hour33=0 then 0 else round(cast( (@acdtime_hour33+@acwtime_hour33) as float)/@logintime_hour33,4) end as UtilizationRate33,
  2265. case when @logintime_hour34=0 then 0 else round(cast( (@acdtime_hour34+@acwtime_hour34) as float)/@logintime_hour34,4) end as UtilizationRate34,
  2266. case when @logintime_hour35=0 then 0 else round(cast( (@acdtime_hour35+@acwtime_hour35) as float)/@logintime_hour35,4) end as UtilizationRate35,
  2267. case when @logintime_hour36=0 then 0 else round(cast( (@acdtime_hour36+@acwtime_hour36) as float)/@logintime_hour36,4) end as UtilizationRate36,
  2268. case when @logintime_hour37=0 then 0 else round(cast( (@acdtime_hour37+@acwtime_hour37) as float)/@logintime_hour37,4) end as UtilizationRate37,
  2269. case when @logintime_hour38=0 then 0 else round(cast( (@acdtime_hour38+@acwtime_hour38) as float)/@logintime_hour38,4) end as UtilizationRate38,
  2270. case when @logintime_hour39=0 then 0 else round(cast( (@acdtime_hour39+@acwtime_hour39) as float)/@logintime_hour39,4) end as UtilizationRate39,
  2271. case when @logintime_hour40=0 then 0 else round(cast( (@acdtime_hour40+@acwtime_hour40) as float)/@logintime_hour40,4) end as UtilizationRate40,
  2272. case when @logintime_hour41=0 then 0 else round(cast( (@acdtime_hour41+@acwtime_hour41) as float)/@logintime_hour41,4) end as UtilizationRate41,
  2273. case when @logintime_hour42=0 then 0 else round(cast( (@acdtime_hour42+@acwtime_hour42) as float)/@logintime_hour42,4) end as UtilizationRate42,
  2274. case when @logintime_hour43=0 then 0 else round(cast( (@acdtime_hour43+@acwtime_hour43) as float)/@logintime_hour43,4) end as UtilizationRate43,
  2275. case when @logintime_hour44=0 then 0 else round(cast( (@acdtime_hour44+@acwtime_hour44) as float)/@logintime_hour44,4) end as UtilizationRate44,
  2276. case when @logintime_hour45=0 then 0 else round(cast( (@acdtime_hour45+@acwtime_hour45) as float)/@logintime_hour45,4) end as UtilizationRate45,
  2277. case when @logintime_hour46=0 then 0 else round(cast( (@acdtime_hour46+@acwtime_hour46) as float)/@logintime_hour46,4) end as UtilizationRate46,
  2278. case when @logintime_hour47=0 then 0 else round(cast( (@acdtime_hour47+@acwtime_hour47) as float)/@logintime_hour47,4) end as UtilizationRate47
  2279. if OBJECT_ID('tempdb..#compute_agentloginlog') is not null
  2280. drop table #compute_agentloginlog
  2281. if OBJECT_ID('tempdb..#compute_agentstatelog') is not null
  2282. drop table #compute_agentstatelog
  2283. if OBJECT_ID('tempdb..#t_stationcallrecord') is not null
  2284. drop table #t_stationcallrecord
  2285. if OBJECT_ID('tempdb..#SearchAgent') is not null
  2286. drop table #SearchAgent
  2287. end