2022051202-UtilizationRateByHour.sql 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635
  1. USE [AECC]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[UtilizationRateByHour] Script Date: 05/12/2022 10:49:14 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER proc [dbo].[UtilizationRateByHour](@searchdatechar varchar(24),@CityCode varchar(10)) as
  9. begin
  10. declare @begintime datetime
  11. declare @endtime datetime
  12. declare @orgId varchar(40)
  13. declare @logintime_hour00 int,
  14. @logintime_hour01 int,
  15. @logintime_hour02 int,
  16. @logintime_hour03 int,
  17. @logintime_hour04 int,
  18. @logintime_hour05 int,
  19. @logintime_hour06 int,
  20. @logintime_hour07 int,
  21. @logintime_hour08 int,
  22. @logintime_hour09 int,
  23. @logintime_hour10 int,
  24. @logintime_hour11 int,
  25. @logintime_hour12 int,
  26. @logintime_hour13 int,
  27. @logintime_hour14 int,
  28. @logintime_hour15 int,
  29. @logintime_hour16 int,
  30. @logintime_hour17 int,
  31. @logintime_hour18 int,
  32. @logintime_hour19 int,
  33. @logintime_hour20 int,
  34. @logintime_hour21 int,
  35. @logintime_hour22 int,
  36. @logintime_hour23 int
  37. declare @acwtime_hour00 int,
  38. @acwtime_hour01 int,
  39. @acwtime_hour02 int,
  40. @acwtime_hour03 int,
  41. @acwtime_hour04 int,
  42. @acwtime_hour05 int,
  43. @acwtime_hour06 int,
  44. @acwtime_hour07 int,
  45. @acwtime_hour08 int,
  46. @acwtime_hour09 int,
  47. @acwtime_hour10 int,
  48. @acwtime_hour11 int,
  49. @acwtime_hour12 int,
  50. @acwtime_hour13 int,
  51. @acwtime_hour14 int,
  52. @acwtime_hour15 int,
  53. @acwtime_hour16 int,
  54. @acwtime_hour17 int,
  55. @acwtime_hour18 int,
  56. @acwtime_hour19 int,
  57. @acwtime_hour20 int,
  58. @acwtime_hour21 int,
  59. @acwtime_hour22 int,
  60. @acwtime_hour23 int
  61. declare @acdtime_hour00 int,
  62. @acdtime_hour01 int,
  63. @acdtime_hour02 int,
  64. @acdtime_hour03 int,
  65. @acdtime_hour04 int,
  66. @acdtime_hour05 int,
  67. @acdtime_hour06 int,
  68. @acdtime_hour07 int,
  69. @acdtime_hour08 int,
  70. @acdtime_hour09 int,
  71. @acdtime_hour10 int,
  72. @acdtime_hour11 int,
  73. @acdtime_hour12 int,
  74. @acdtime_hour13 int,
  75. @acdtime_hour14 int,
  76. @acdtime_hour15 int,
  77. @acdtime_hour16 int,
  78. @acdtime_hour17 int,
  79. @acdtime_hour18 int,
  80. @acdtime_hour19 int,
  81. @acdtime_hour20 int,
  82. @acdtime_hour21 int,
  83. @acdtime_hour22 int,
  84. @acdtime_hour23 int
  85. declare @ihour int
  86. declare
  87. @i_acwtime1 int,
  88. @i_acwtime2 int,
  89. @i_acwtime3 int,
  90. @i_acwtime4 int,
  91. @i_acwtime int
  92. declare
  93. @i_stafftime1 int,
  94. @i_stafftime2 int,
  95. @i_stafftime3 int,
  96. @i_stafftime4 int,
  97. @i_stafftime int
  98. set @begintime=convert(datetime,@searchdatechar)
  99. set @endtime=DATEADD(day,1,@begintime)
  100. --set @begintime='2022-05-09'
  101. --set @endtime='2022-05-10'
  102. set @orgId='b05d5ac9-82b6-4abe-b343-36ddc94672d1'
  103. if (@CityCode='SZ')
  104. set @orgId='2b568031-39a1-4117-9927-39b7ade19e66'
  105. if (@CityCode='JN')
  106. set @orgId='f454f95c-9ab2-4499-936f-e746195c7487'
  107. if OBJECT_ID('tempdb..#compute_agentloginlog') is not null
  108. drop table #compute_agentloginlog
  109. if OBJECT_ID('tempdb..#compute_agentstatelog') is not null
  110. drop table #compute_agentstatelog
  111. if OBJECT_ID('tempdb..#t_stationcallrecord') is not null
  112. drop table #t_stationcallrecord
  113. if OBJECT_ID('tempdb..#SearchAgent') is not null
  114. drop table #SearchAgent
  115. select distinct Agent.Agent into #SearchAgent from Agent with(nolock) join Org_Agent with(nolock) on
  116. Agent.AgentID=Org_Agent.AgentID join Organization with(nolock) on Org_Agent.OrgID=Organization.OrgID
  117. and Org_Agent.OrgID in (@orgId)
  118. --某天每个小时的登录总时长
  119. select * into #compute_agentloginlog from agentloginlog
  120. where 1=1
  121. and (
  122. logintime >= @begintime and logintime < @endtime and logouttime >= @begintime and logouttime < @endtime
  123. or (logintime <= @begintime and (logouttime >= @endtime or LogoutTime is null))
  124. or (logintime <= @begintime and logouttime >= @begintime and logouttime < @endtime)
  125. or (logintime >= @begintime and logintime < @endtime and (logouttime > @endtime or LogoutTime is null))
  126. )
  127. and agentid in (select agent from #SearchAgent)
  128. set @ihour=1;
  129. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  130. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  131. from #compute_agentloginlog
  132. where
  133. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  134. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  135. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  136. from #compute_agentloginlog
  137. where
  138. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  139. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  140. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  141. from #compute_agentloginlog
  142. where
  143. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  144. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  145. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  146. from #compute_agentloginlog
  147. where
  148. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  149. set @logintime_hour00=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  150. set @ihour=@ihour+1;
  151. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  152. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  153. from #compute_agentloginlog
  154. where
  155. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  156. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  157. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  158. from #compute_agentloginlog
  159. where
  160. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  161. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  162. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  163. from #compute_agentloginlog
  164. where
  165. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  166. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  167. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  168. from #compute_agentloginlog
  169. where
  170. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  171. set @logintime_hour01=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  172. set @ihour=@ihour+1;
  173. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  174. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  175. from #compute_agentloginlog
  176. where
  177. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  178. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  179. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  180. from #compute_agentloginlog
  181. where
  182. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  183. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  184. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  185. from #compute_agentloginlog
  186. where
  187. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  188. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  189. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  190. from #compute_agentloginlog
  191. where
  192. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  193. set @logintime_hour02=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  194. set @ihour=@ihour+1;
  195. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  196. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  197. from #compute_agentloginlog
  198. where
  199. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  200. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  201. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  202. from #compute_agentloginlog
  203. where
  204. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  205. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  206. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  207. from #compute_agentloginlog
  208. where
  209. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  210. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  211. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  212. from #compute_agentloginlog
  213. where
  214. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  215. set @logintime_hour03=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  216. set @ihour=@ihour+1;
  217. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  218. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  219. from #compute_agentloginlog
  220. where
  221. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  222. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  223. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  224. from #compute_agentloginlog
  225. where
  226. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  227. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  228. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  229. from #compute_agentloginlog
  230. where
  231. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  232. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  233. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  234. from #compute_agentloginlog
  235. where
  236. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  237. set @logintime_hour04=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  238. set @ihour=@ihour+1;
  239. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  240. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  241. from #compute_agentloginlog
  242. where
  243. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  244. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  245. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  246. from #compute_agentloginlog
  247. where
  248. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  249. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  250. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  251. from #compute_agentloginlog
  252. where
  253. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  254. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  255. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  256. from #compute_agentloginlog
  257. where
  258. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  259. set @logintime_hour05=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  260. set @ihour=@ihour+1;
  261. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  262. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  263. from #compute_agentloginlog
  264. where
  265. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  266. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  267. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  268. from #compute_agentloginlog
  269. where
  270. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  271. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  272. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  273. from #compute_agentloginlog
  274. where
  275. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  276. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  277. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  278. from #compute_agentloginlog
  279. where
  280. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  281. set @logintime_hour06=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  282. set @ihour=@ihour+1;
  283. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  284. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  285. from #compute_agentloginlog
  286. where
  287. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  288. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  289. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  290. from #compute_agentloginlog
  291. where
  292. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  293. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  294. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  295. from #compute_agentloginlog
  296. where
  297. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  298. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  299. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  300. from #compute_agentloginlog
  301. where
  302. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  303. set @logintime_hour07=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  304. set @ihour=@ihour+1;
  305. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  306. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  307. from #compute_agentloginlog
  308. where
  309. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  310. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  311. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  312. from #compute_agentloginlog
  313. where
  314. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  315. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  316. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  317. from #compute_agentloginlog
  318. where
  319. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  320. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  321. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  322. from #compute_agentloginlog
  323. where
  324. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  325. set @logintime_hour08=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  326. set @ihour=@ihour+1;
  327. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  328. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  329. from #compute_agentloginlog
  330. where
  331. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  332. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  333. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  334. from #compute_agentloginlog
  335. where
  336. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  337. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  338. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  339. from #compute_agentloginlog
  340. where
  341. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  342. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  343. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  344. from #compute_agentloginlog
  345. where
  346. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  347. set @logintime_hour09=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  348. set @ihour=@ihour+1;
  349. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  350. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  351. from #compute_agentloginlog
  352. where
  353. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  354. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  355. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  356. from #compute_agentloginlog
  357. where
  358. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  359. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  360. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  361. from #compute_agentloginlog
  362. where
  363. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  364. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  365. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  366. from #compute_agentloginlog
  367. where
  368. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  369. set @logintime_hour10=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  370. set @ihour=@ihour+1;
  371. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  372. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  373. from #compute_agentloginlog
  374. where
  375. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  376. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  377. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  378. from #compute_agentloginlog
  379. where
  380. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  381. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  382. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  383. from #compute_agentloginlog
  384. where
  385. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  386. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  387. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  388. from #compute_agentloginlog
  389. where
  390. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  391. set @logintime_hour11=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  392. set @ihour=@ihour+1;
  393. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  394. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  395. from #compute_agentloginlog
  396. where
  397. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  398. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  399. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  400. from #compute_agentloginlog
  401. where
  402. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  403. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  404. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  405. from #compute_agentloginlog
  406. where
  407. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  408. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  409. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  410. from #compute_agentloginlog
  411. where
  412. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  413. set @logintime_hour12=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  414. set @ihour=@ihour+1;
  415. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  416. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  417. from #compute_agentloginlog
  418. where
  419. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  420. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  421. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  422. from #compute_agentloginlog
  423. where
  424. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  425. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  426. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  427. from #compute_agentloginlog
  428. where
  429. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  430. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  431. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  432. from #compute_agentloginlog
  433. where
  434. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  435. set @logintime_hour13=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  436. set @ihour=@ihour+1;
  437. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  438. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  439. from #compute_agentloginlog
  440. where
  441. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  442. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  443. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  444. from #compute_agentloginlog
  445. where
  446. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  447. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  448. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  449. from #compute_agentloginlog
  450. where
  451. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  452. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  453. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  454. from #compute_agentloginlog
  455. where
  456. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  457. set @logintime_hour14=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  458. set @ihour=@ihour+1;
  459. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  460. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  461. from #compute_agentloginlog
  462. where
  463. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  464. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  465. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  466. from #compute_agentloginlog
  467. where
  468. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  469. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  470. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  471. from #compute_agentloginlog
  472. where
  473. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  474. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  475. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  476. from #compute_agentloginlog
  477. where
  478. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  479. set @logintime_hour15=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  480. set @ihour=@ihour+1;
  481. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  482. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  483. from #compute_agentloginlog
  484. where
  485. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  486. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  487. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  488. from #compute_agentloginlog
  489. where
  490. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  491. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  492. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  493. from #compute_agentloginlog
  494. where
  495. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  496. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  497. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  498. from #compute_agentloginlog
  499. where
  500. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  501. set @logintime_hour16=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  502. set @ihour=@ihour+1;
  503. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  504. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  505. from #compute_agentloginlog
  506. where
  507. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  508. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  509. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  510. from #compute_agentloginlog
  511. where
  512. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  513. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  514. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  515. from #compute_agentloginlog
  516. where
  517. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  518. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  519. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  520. from #compute_agentloginlog
  521. where
  522. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  523. set @logintime_hour17=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  524. set @ihour=@ihour+1;
  525. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  526. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  527. from #compute_agentloginlog
  528. where
  529. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  530. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  531. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  532. from #compute_agentloginlog
  533. where
  534. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  535. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  536. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  537. from #compute_agentloginlog
  538. where
  539. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  540. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  541. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  542. from #compute_agentloginlog
  543. where
  544. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  545. set @logintime_hour18=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  546. set @ihour=@ihour+1;
  547. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  548. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  549. from #compute_agentloginlog
  550. where
  551. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  552. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  553. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  554. from #compute_agentloginlog
  555. where
  556. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  557. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  558. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  559. from #compute_agentloginlog
  560. where
  561. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  562. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  563. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  564. from #compute_agentloginlog
  565. where
  566. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  567. set @logintime_hour19=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  568. set @ihour=@ihour+1;
  569. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  570. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  571. from #compute_agentloginlog
  572. where
  573. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  574. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  575. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  576. from #compute_agentloginlog
  577. where
  578. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  579. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  580. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  581. from #compute_agentloginlog
  582. where
  583. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  584. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  585. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  586. from #compute_agentloginlog
  587. where
  588. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  589. set @logintime_hour20=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  590. set @ihour=@ihour+1;
  591. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  592. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  593. from #compute_agentloginlog
  594. where
  595. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  596. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  597. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  598. from #compute_agentloginlog
  599. where
  600. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  601. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  602. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  603. from #compute_agentloginlog
  604. where
  605. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  606. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  607. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  608. from #compute_agentloginlog
  609. where
  610. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  611. set @logintime_hour21=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  612. set @ihour=@ihour+1;
  613. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  614. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  615. from #compute_agentloginlog
  616. where
  617. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  618. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  619. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  620. from #compute_agentloginlog
  621. where
  622. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  623. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  624. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  625. from #compute_agentloginlog
  626. where
  627. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  628. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  629. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  630. from #compute_agentloginlog
  631. where
  632. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  633. set @logintime_hour22=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  634. set @ihour=@ihour+1;
  635. --登入时间和登出时间都在@row_date_a和@row_date_b之间,此时计算logouttime-logintime=?
  636. select @i_stafftime1=isnull(sum(isnull(datediff(ss,logintime, logouttime),0)),0)
  637. from #compute_agentloginlog
  638. where
  639. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  640. --登入时间在@row_date_a之前,登出时间在@row_date_b之后或者没有登出时间,此时计算@intrvl*3600秒=?
  641. select @i_stafftime2=isnull(sum(@ihour*3600),0)
  642. from #compute_agentloginlog
  643. where
  644. logintime <= @begintime and (logouttime >= dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  645. --登入时间在@row_date_a之前,登出时间在@row_date_a和@row_date_b之间,此时计算logouttime-@row_date_a=?
  646. select @i_stafftime3=isnull(sum(isnull(datediff(ss,@begintime, logouttime),0)),0)
  647. from #compute_agentloginlog
  648. where
  649. logintime <= @begintime and logouttime >= @begintime and logouttime < dateadd(hour,@ihour,@begintime)
  650. --登入时间在@row_date_a和@row_date_b之间,登出时间在@row_date_b之后或者没有登出时间
  651. select @i_stafftime4=isnull(sum(isnull(datediff(ss,logintime, dateadd(hour,@ihour,@begintime)),0)),0)
  652. from #compute_agentloginlog
  653. where
  654. logintime >= @begintime and logintime < dateadd(hour,@ihour,@begintime) and (logouttime > dateadd(hour,@ihour,@begintime) or LogoutTime is null)
  655. set @logintime_hour23=@i_stafftime1+@i_stafftime2+@i_stafftime3+@i_stafftime4
  656. --每小时总的话后总时长
  657. select * into #compute_agentstatelog from agentstatelog
  658. where 1=1 and state=2
  659. and (
  660. (begintime >= @begintime and begintime < @endtime and endtime >= @begintime and endtime < @endtime )
  661. or (begintime <= @begintime and (Endtime >= @endtime or Endtime is null))
  662. or (begintime < @begintime and endtime >= @begintime and endtime < @endtime)
  663. or (begintime >= @begintime and begintime < @endtime and (Endtime > @endtime or Endtime is null))
  664. )
  665. and agentid in (select Agent from #SearchAgent)
  666. set @ihour=1;
  667. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  668. where
  669. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  670. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  671. where
  672. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  673. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  674. where
  675. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  676. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  677. where
  678. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  679. set @acwtime_hour00=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  680. set @ihour=@ihour+1;
  681. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  682. where
  683. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  684. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  685. where
  686. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  687. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  688. where
  689. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  690. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  691. where
  692. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  693. set @acwtime_hour01=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  694. set @ihour=@ihour+1;
  695. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  696. where
  697. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  698. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  699. where
  700. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  701. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  702. where
  703. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  704. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  705. where
  706. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  707. set @acwtime_hour02=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  708. set @ihour=@ihour+1;
  709. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  710. where
  711. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  712. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  713. where
  714. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  715. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  716. where
  717. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  718. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  719. where
  720. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  721. set @acwtime_hour03=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  722. set @ihour=@ihour+1;
  723. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  724. where
  725. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  726. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  727. where
  728. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  729. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  730. where
  731. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  732. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  733. where
  734. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  735. set @acwtime_hour04=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  736. set @ihour=@ihour+1;
  737. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  738. where
  739. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  740. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  741. where
  742. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  743. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  744. where
  745. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  746. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  747. where
  748. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  749. set @acwtime_hour05=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  750. set @ihour=@ihour+1;
  751. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  752. where
  753. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  754. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  755. where
  756. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  757. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  758. where
  759. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  760. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  761. where
  762. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  763. set @acwtime_hour06=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  764. set @ihour=@ihour+1;
  765. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  766. where
  767. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  768. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  769. where
  770. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  771. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  772. where
  773. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  774. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  775. where
  776. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  777. set @acwtime_hour07=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  778. set @ihour=@ihour+1;
  779. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  780. where
  781. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  782. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  783. where
  784. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  785. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  786. where
  787. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  788. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  789. where
  790. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  791. set @acwtime_hour08=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  792. set @ihour=@ihour+1;
  793. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  794. where
  795. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  796. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  797. where
  798. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  799. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  800. where
  801. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  802. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  803. where
  804. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  805. set @acwtime_hour09=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  806. set @ihour=@ihour+1;
  807. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  808. where
  809. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  810. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  811. where
  812. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  813. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  814. where
  815. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  816. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  817. where
  818. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  819. set @acwtime_hour10=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  820. set @ihour=@ihour+1;
  821. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  822. where
  823. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  824. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  825. where
  826. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  827. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  828. where
  829. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  830. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  831. where
  832. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  833. set @acwtime_hour11=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  834. set @ihour=@ihour+1;
  835. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  836. where
  837. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  838. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  839. where
  840. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  841. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  842. where
  843. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  844. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  845. where
  846. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  847. set @acwtime_hour12=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  848. set @ihour=@ihour+1;
  849. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  850. where
  851. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  852. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  853. where
  854. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  855. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  856. where
  857. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  858. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  859. where
  860. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  861. set @acwtime_hour13=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  862. set @ihour=@ihour+1;
  863. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  864. where
  865. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  866. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  867. where
  868. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  869. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  870. where
  871. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  872. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  873. where
  874. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  875. set @acwtime_hour14=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  876. set @ihour=@ihour+1;
  877. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  878. where
  879. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  880. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  881. where
  882. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  883. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  884. where
  885. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  886. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  887. where
  888. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  889. set @acwtime_hour15=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  890. set @ihour=@ihour+1;
  891. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  892. where
  893. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  894. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  895. where
  896. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  897. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  898. where
  899. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  900. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  901. where
  902. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  903. set @acwtime_hour16=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  904. set @ihour=@ihour+1;
  905. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  906. where
  907. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  908. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  909. where
  910. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  911. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  912. where
  913. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  914. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  915. where
  916. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  917. set @acwtime_hour17=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  918. set @ihour=@ihour+1;
  919. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  920. where
  921. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  922. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  923. where
  924. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  925. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  926. where
  927. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  928. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  929. where
  930. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  931. set @acwtime_hour18=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  932. set @ihour=@ihour+1;
  933. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  934. where
  935. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  936. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  937. where
  938. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  939. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  940. where
  941. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  942. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  943. where
  944. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  945. set @acwtime_hour19=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  946. set @ihour=@ihour+1;
  947. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  948. where
  949. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  950. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  951. where
  952. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  953. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  954. where
  955. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  956. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  957. where
  958. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  959. set @acwtime_hour20=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  960. set @ihour=@ihour+1;
  961. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  962. where
  963. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  964. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  965. where
  966. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  967. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  968. where
  969. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  970. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  971. where
  972. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  973. set @acwtime_hour21=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  974. set @ihour=@ihour+1;
  975. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  976. where
  977. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  978. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  979. where
  980. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  981. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  982. where
  983. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  984. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  985. where
  986. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  987. set @acwtime_hour22=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  988. set @ihour=@ihour+1;
  989. select @i_acwtime1=isnull(sum(isnull(datediff(ss,begintime, endtime),0)),0) from #compute_agentstatelog
  990. where
  991. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  992. select @i_acwtime2=isnull(sum(@ihour*3600),0) from #compute_agentstatelog
  993. where
  994. begintime <= @begintime and (Endtime >= dateadd(hour,@ihour,@begintime) or Endtime is null)
  995. select @i_acwtime3=isnull(sum(isnull(datediff(ss,@begintime, endtime),0)),0) from #compute_agentstatelog
  996. where
  997. begintime < @begintime and endtime >= @begintime and endtime < dateadd(hour,@ihour,@begintime)
  998. select @i_acwtime4=isnull(sum(isnull(datediff(ss,begintime, dateadd(hour,@ihour,@begintime)),0)),0) from #compute_agentstatelog
  999. where
  1000. begintime >= @begintime and begintime < dateadd(hour,@ihour,@begintime) and (Endtime > dateadd(hour,@ihour,@begintime) or Endtime is null)
  1001. set @acwtime_hour23=@i_acwtime1+@i_acwtime2+@i_acwtime3+@i_acwtime4
  1002. --每小时总的通话总时长
  1003. select * into #t_stationcallrecord
  1004. from stationcallrecord with(nolock)
  1005. where 1=1
  1006. and (End_Time >=@begintime and End_Time <@endtime)
  1007. --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')
  1008. and calldirect=1
  1009. and split != ''
  1010. and AgentID in
  1011. (
  1012. select Agent from #SearchAgent
  1013. );
  1014. set @ihour=1;
  1015. select @acdtime_hour00=
  1016. isnull(sum(talk_dur),0)
  1017. from #t_stationcallrecord
  1018. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1019. ;
  1020. set @ihour=@ihour+1;
  1021. select @acdtime_hour01=
  1022. isnull(sum(talk_dur),0)
  1023. from #t_stationcallrecord
  1024. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1025. ;
  1026. set @ihour=@ihour+1;
  1027. select @acdtime_hour02=
  1028. isnull(sum(talk_dur),0)
  1029. from #t_stationcallrecord
  1030. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1031. ;
  1032. set @ihour=@ihour+1;
  1033. select @acdtime_hour03=
  1034. isnull(sum(talk_dur),0)
  1035. from #t_stationcallrecord
  1036. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1037. ;
  1038. set @ihour=@ihour+1;
  1039. select @acdtime_hour04=
  1040. isnull(sum(talk_dur),0)
  1041. from #t_stationcallrecord
  1042. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1043. ;
  1044. set @ihour=@ihour+1;
  1045. select @acdtime_hour05=
  1046. isnull(sum(talk_dur),0)
  1047. from #t_stationcallrecord
  1048. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1049. ;
  1050. set @ihour=@ihour+1;
  1051. select @acdtime_hour06=
  1052. isnull(sum(talk_dur),0)
  1053. from #t_stationcallrecord
  1054. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1055. ;
  1056. set @ihour=@ihour+1;
  1057. select @acdtime_hour07=
  1058. isnull(sum(talk_dur),0)
  1059. from #t_stationcallrecord
  1060. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1061. ;
  1062. set @ihour=@ihour+1;
  1063. select @acdtime_hour08=
  1064. isnull(sum(talk_dur),0)
  1065. from #t_stationcallrecord
  1066. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1067. ;
  1068. set @ihour=@ihour+1;
  1069. select @acdtime_hour09=
  1070. isnull(sum(talk_dur),0)
  1071. from #t_stationcallrecord
  1072. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1073. ;
  1074. set @ihour=@ihour+1;
  1075. select @acdtime_hour10=
  1076. isnull(sum(talk_dur),0)
  1077. from #t_stationcallrecord
  1078. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1079. ;
  1080. set @ihour=@ihour+1;
  1081. select @acdtime_hour11=
  1082. isnull(sum(talk_dur),0)
  1083. from #t_stationcallrecord
  1084. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1085. ;
  1086. set @ihour=@ihour+1;
  1087. select @acdtime_hour12=
  1088. isnull(sum(talk_dur),0)
  1089. from #t_stationcallrecord
  1090. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1091. ;
  1092. set @ihour=@ihour+1;
  1093. select @acdtime_hour13=
  1094. isnull(sum(talk_dur),0)
  1095. from #t_stationcallrecord
  1096. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1097. ;
  1098. set @ihour=@ihour+1;
  1099. select @acdtime_hour14=
  1100. isnull(sum(talk_dur),0)
  1101. from #t_stationcallrecord
  1102. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1103. ;
  1104. set @ihour=@ihour+1;
  1105. select @acdtime_hour15=
  1106. isnull(sum(talk_dur),0)
  1107. from #t_stationcallrecord
  1108. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1109. ;
  1110. set @ihour=@ihour+1;
  1111. select @acdtime_hour16=
  1112. isnull(sum(talk_dur),0)
  1113. from #t_stationcallrecord
  1114. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1115. ;
  1116. set @ihour=@ihour+1;
  1117. select @acdtime_hour17=
  1118. isnull(sum(talk_dur),0)
  1119. from #t_stationcallrecord
  1120. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1121. ;
  1122. set @ihour=@ihour+1;
  1123. select @acdtime_hour18=
  1124. isnull(sum(talk_dur),0)
  1125. from #t_stationcallrecord
  1126. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1127. ;
  1128. set @ihour=@ihour+1;
  1129. select @acdtime_hour19=
  1130. isnull(sum(talk_dur),0)
  1131. from #t_stationcallrecord
  1132. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1133. ;
  1134. set @ihour=@ihour+1;
  1135. select @acdtime_hour20=
  1136. isnull(sum(talk_dur),0)
  1137. from #t_stationcallrecord
  1138. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1139. ;
  1140. set @ihour=@ihour+1;
  1141. select @acdtime_hour21=
  1142. isnull(sum(talk_dur),0)
  1143. from #t_stationcallrecord
  1144. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1145. ;
  1146. set @ihour=@ihour+1;
  1147. select @acdtime_hour22=
  1148. isnull(sum(talk_dur),0)
  1149. from #t_stationcallrecord
  1150. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1151. ;
  1152. set @ihour=@ihour+1;
  1153. select @acdtime_hour23=
  1154. isnull(sum(talk_dur),0)
  1155. from #t_stationcallrecord
  1156. where 1=1 and (End_Time >=@begintime and End_Time <dateadd(hour,@ihour,@begintime))
  1157. ;
  1158. --select * into ##compute_agentloginlog from #compute_agentloginlog
  1159. --select @logintime_hour00 logintime_hour00,@acdtime_hour00 acdtime_hour00,@acwtime_hour00 acwtime_hour00
  1160. select case when @logintime_hour00=0 then 0 else round(cast( (@acdtime_hour00+@acwtime_hour00) as float)/@logintime_hour00,4) end as UtilizationRate00,
  1161. case when @logintime_hour01=0 then 0 else round(cast( (@acdtime_hour01+@acwtime_hour01) as float)/@logintime_hour01,4) end as UtilizationRate01,
  1162. case when @logintime_hour02=0 then 0 else round(cast( (@acdtime_hour02+@acwtime_hour02) as float)/@logintime_hour02,4) end as UtilizationRate02,
  1163. case when @logintime_hour03=0 then 0 else round(cast( (@acdtime_hour03+@acwtime_hour03) as float)/@logintime_hour03,4) end as UtilizationRate03,
  1164. case when @logintime_hour04=0 then 0 else round(cast( (@acdtime_hour04+@acwtime_hour04) as float)/@logintime_hour04,4) end as UtilizationRate04,
  1165. case when @logintime_hour05=0 then 0 else round(cast( (@acdtime_hour05+@acwtime_hour05) as float)/@logintime_hour05,4) end as UtilizationRate05,
  1166. case when @logintime_hour06=0 then 0 else round(cast( (@acdtime_hour06+@acwtime_hour06) as float)/@logintime_hour06,4) end as UtilizationRate06,
  1167. case when @logintime_hour07=0 then 0 else round(cast( (@acdtime_hour07+@acwtime_hour07) as float)/@logintime_hour07,4) end as UtilizationRate07,
  1168. case when @logintime_hour08=0 then 0 else round(cast( (@acdtime_hour08+@acwtime_hour08) as float)/@logintime_hour08,4) end as UtilizationRate08,
  1169. case when @logintime_hour09=0 then 0 else round(cast( (@acdtime_hour09+@acwtime_hour09) as float)/@logintime_hour09,4) end as UtilizationRate09,
  1170. case when @logintime_hour10=0 then 0 else round(cast( (@acdtime_hour10+@acwtime_hour10) as float)/@logintime_hour10,4) end as UtilizationRate10,
  1171. case when @logintime_hour11=0 then 0 else round(cast( (@acdtime_hour11+@acwtime_hour11) as float)/@logintime_hour11,4) end as UtilizationRate11,
  1172. case when @logintime_hour12=0 then 0 else round(cast( (@acdtime_hour12+@acwtime_hour12) as float)/@logintime_hour12,4) end as UtilizationRate12,
  1173. case when @logintime_hour13=0 then 0 else round(cast( (@acdtime_hour13+@acwtime_hour13) as float)/@logintime_hour13,4) end as UtilizationRate13,
  1174. case when @logintime_hour14=0 then 0 else round(cast( (@acdtime_hour14+@acwtime_hour14) as float)/@logintime_hour14,4) end as UtilizationRate14,
  1175. case when @logintime_hour15=0 then 0 else round(cast( (@acdtime_hour15+@acwtime_hour15) as float)/@logintime_hour15,4) end as UtilizationRate15,
  1176. case when @logintime_hour16=0 then 0 else round(cast( (@acdtime_hour16+@acwtime_hour16) as float)/@logintime_hour16,4) end as UtilizationRate16,
  1177. case when @logintime_hour17=0 then 0 else round(cast( (@acdtime_hour17+@acwtime_hour17) as float)/@logintime_hour17,4) end as UtilizationRate17,
  1178. case when @logintime_hour18=0 then 0 else round(cast( (@acdtime_hour18+@acwtime_hour18) as float)/@logintime_hour18,4) end as UtilizationRate18,
  1179. case when @logintime_hour19=0 then 0 else round(cast( (@acdtime_hour19+@acwtime_hour19) as float)/@logintime_hour19,4) end as UtilizationRate19,
  1180. case when @logintime_hour20=0 then 0 else round(cast( (@acdtime_hour20+@acwtime_hour20) as float)/@logintime_hour20,4) end as UtilizationRate20,
  1181. case when @logintime_hour21=0 then 0 else round(cast( (@acdtime_hour21+@acwtime_hour21) as float)/@logintime_hour21,4) end as UtilizationRate21,
  1182. case when @logintime_hour22=0 then 0 else round(cast( (@acdtime_hour22+@acwtime_hour22) as float)/@logintime_hour22,4) end as UtilizationRate22,
  1183. case when @logintime_hour23=0 then 0 else round(cast( (@acdtime_hour23+@acwtime_hour23) as float)/@logintime_hour23,4) end as UtilizationRate23
  1184. if OBJECT_ID('tempdb..#compute_agentloginlog') is not null
  1185. drop table #compute_agentloginlog
  1186. if OBJECT_ID('tempdb..#compute_agentstatelog') is not null
  1187. drop table #compute_agentstatelog
  1188. if OBJECT_ID('tempdb..#t_stationcallrecord') is not null
  1189. drop table #t_stationcallrecord
  1190. if OBJECT_ID('tempdb..#SearchAgent') is not null
  1191. drop table #SearchAgent
  1192. end