2022050901-UtilizationRateByHour.sql 71 KB

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