Advertisement
WorkAkkaunt

09 Oktell

Jul 17th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.44 KB | None | 0 0
  1. if (@interval is null)
  2.     set @interval = 2
  3.  
  4. if not (@interval in (1, 2, 3))
  5.     set @interval = 2
  6.  
  7. declare @intMin int
  8.  
  9. select @intMin = case @interval
  10.     when 1 then 15
  11.     when 2 then 30
  12.     when 3 then 60
  13. end
  14.  
  15.  
  16. create table #taskstmp([id] uniqueidentifier)
  17.  
  18. insert into #taskstmp
  19.     select cast(id as uniqueidentifier) from @tasks
  20. if ( @@rowcount = 0 )
  21.     insert into #taskstmp
  22.     SELECT  [Id]
  23.     FROM [oktell_cc_temp].[dbo].[A_Cube_CC_Cat_Task]
  24.     Where Isoutput = 0
  25.    
  26. select case @interval
  27.             when 1 then convert(nvarchar(5),[time],108) + ' - ' + convert(nvarchar(5),dateadd(mi,15,[time]),108)
  28.             when 2 then convert(nvarchar(5),[time],108) + ' - ' + convert(nvarchar(5),dateadd(mi,30,[time]),108)
  29.             when 3 then convert(nvarchar(5),[time],108) + ' - ' + convert(nvarchar(5),dateadd(hh,1,[time]),108)
  30.         end time,
  31.     total, suc, failed,
  32.     round(suc*100.0e0/total, 2) prc, round(failed*100.0e0/total, 2) lcr, servdx,
  33.     round(case @slist
  34.         when 1 then case when suc=0 then 0 else servdx*100.0e0/suc end
  35.         when 2 then case when total=0 then 0 else servdx*100.0e0/total end
  36.         when 3 then case when suc+lostx=0 then 0 else servdx*100.0e0/(suc+lostx) end
  37.         when 4 then case when total=0 then 0 else slx*100.0e0/total end
  38.     end, 2) slx
  39. from(
  40. select [time], count(*) total, sum(suc) suc, sum(unsuc) failed,
  41. sum(case when suc=1 and lenQueue<@xline then 1 else 0 end) servdx,
  42. sum(case when lenQueue<@xline then 1 else 0 end) slx,
  43. sum(case when unsuc=1 and lenqueue>@xline then 1 else 0 end) lostx
  44. from(
  45.     select min([time]) [time], max(suc) suc, min(unsuc) unsuc, max(LenQueue) LenQueue
  46.     from(
  47.         select IdChain,
  48.         case when (CallResult = 5 or CallResult = 18) then 1 else 0 end suc,
  49.         case when not (CallResult = 5 or CallResult = 18) then 1 else 0 end unsuc,
  50.         case when (CallResult = 5 or CallResult = 18) and LenQueue<@xline then 1 else 0 end servdx,
  51.         case when LenQueue<@xline then 1 else 0 end slx,
  52.         case when LenQueue>@xline and CallResult != 5 and CallResult != 18 then 1 else 0 end lostx,
  53.         LenQueue, [time]
  54.         from(
  55.             select  idchain,
  56.             callresult,
  57.             lenqueue,          
  58.             [time] = DATEADD(mi, DATEDIFF(mi, '19000101', TimeStart)/@intMin*@intMin, '19000101')
  59.             from [oktell_cc_temp].[dbo].[A_Cube_CC_EffortConnections]
  60.             where DateTimeStart between @dt1 and @dt2
  61.                 and IdChain is not null
  62.                 and IdTask in (select id from #taskstmp)
  63.                 and IsOutput = 0
  64.         )t
  65.     )t
  66.     group by IdChain)t
  67. group by time)t
  68. order by t.time
  69.  
  70. drop table #taskstmp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement