Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. declare @id table (id uniqueidentifier)
  2. insert into @id
  3. select id from [oktell_settings].[dbo].[A_Users]
  4. where ParentGroupID = @group
  5.  
  6. Select US.Name,Tb2.[CountCall],Tb2.[TIme]
  7. FROM
  8. (
  9. Select Count(id) [CountCall], oktell.dbo.GetTimeFromSecond(sum(Time)) [TIme], [UserId]
  10. FROM
  11. (
  12. select id, datediff(ss,TimeAnswer, TimeStop) [Time], AUserId [UserId]
  13. FROM [oktell].[dbo].[A_Stat_Connections_1x1]
  14. where AuserID in (select * from @id)
  15. and TimeStart between @dt1 and @dt2
  16. and CAST(CONVERT(CHAR(10), TimeStart, 108) AS DATETIME) between @tm1 and @tm2
  17.  
  18. Union All
  19.  
  20. select id, datediff(ss,TimeAnswer, TimeStop) [Time], BUserId [UserId]
  21. FROM [oktell].[dbo].[A_Stat_Connections_1x1]
  22. where BuserID in (select * from @id)
  23. and TimeStart between @dt1 and @dt2
  24. and CAST(CONVERT(CHAR(10), TimeStart, 108) AS DATETIME) between @tm1 and @tm2
  25.  
  26. )Tb1
  27. Group BY [UserId]
  28. )Tb2,
  29. [oktell_settings].[dbo].[A_Users] US
  30. Where Tb2.UserId = US.Id
  31. Order by name asc
  32.  
  33. Я пробовал вот так сделать.
  34.  
  35. declare @id table (id uniqueidentifier)
  36. insert into @id
  37. select id from [oktell_settings].[dbo].[A_Users]
  38. where ParentGroupID = @group
  39.  
  40. Select US.Name,Tb2.[CountCall],Tb2.[TIme], Tb2.[LengthSec]
  41. FROM
  42. (
  43. Select Count(id) [CountCall], oktell.dbo.GetTimeFromSecond(sum(Time)) [TIme], [LengthSec], [UserId]
  44. FROM
  45. (
  46. select kk.id, datediff(ss,TimeAnswer, kk.TimeStop) [Time], kk.AUserId [UserId] , ee.LengthSec [LengthSec]
  47. FROM [oktell].[dbo].[A_Stat_Connections_1x1] kk, [A_CallCenter_UserStateHistory] ee
  48. where kk.AuserID in (select * from @id)
  49. and kk.TimeStart between @dt1 and @dt2
  50. and CAST(CONVERT(CHAR(10), kk.TimeStart, 108) AS DATETIME) between @tm1 and @tm2
  51. and OperatorId=kk.AuserID and State=3 and ee.TimeEnter between @dt1 and @dt2 and CAST(CONVERT(CHAR(10), ee.TimeEnter, 108) AS DATETIME) between @tm1 and @tm2
  52.  
  53. Union All
  54.  
  55. select tt.id, datediff(ss,TimeAnswer, tt.TimeStop) [Time], tt.BUserId [UserId] , ww.LengthSec [LengthSec]
  56. FROM [oktell].[dbo].[A_Stat_Connections_1x1] tt, [A_CallCenter_UserStateHistory] ww
  57. where tt.BuserID in (select * from @id)
  58. and tt.TimeStart between @dt1 and @dt2
  59. and CAST(CONVERT(CHAR(10), tt.TimeStart, 108) AS DATETIME) between @tm1 and @tm2
  60. and OperatorId=tt.BuserID and State=3 and ww.TimeEnter between @dt1 and @dt2 and CAST(CONVERT(CHAR(10), ww.TimeEnter, 108) AS DATETIME) between @tm1 and @tm2
  61.  
  62. )Tb1
  63. Group BY [UserId] , [LengthSec]
  64. )Tb2,
  65. [oktell_settings].[dbo].[A_Users] US
  66. Where Tb2.UserId = US.Id
  67. Order by name asc
  68.  
  69. Select US.Name,Tb2.[CountCall],Tb2.[TIme], ee.LengthSec
  70. FROM
  71. (
  72. Select Count(id) [CountCall], oktell.dbo.GetTimeFromSecond(sum(Time)) [TIme], [UserId]
  73. FROM
  74. (
  75. select id, datediff(ss,TimeAnswer, TimeStop) [Time], AUserId [UserId]
  76. FROM [oktell].[dbo].[A_Stat_Connections_1x1]
  77. where AuserID in (select * from @id)
  78. and TimeStart between @dt1 and @dt2
  79. and CAST(CONVERT(CHAR(10), TimeStart, 108) AS DATETIME) between @tm1 and @tm2
  80.  
  81. Union All
  82.  
  83. select id, datediff(ss,TimeAnswer, TimeStop) [Time], BUserId [UserId]
  84. FROM [oktell].[dbo].[A_Stat_Connections_1x1]
  85. where BuserID in (select * from @id)
  86. and TimeStart between @dt1 and @dt2
  87. and CAST(CONVERT(CHAR(10), TimeStart, 108) AS DATETIME) between @tm1 and @tm2
  88.  
  89. )Tb1
  90. Group BY [UserId]
  91. )Tb2,
  92. [oktell_settings].[dbo].[A_Users] US, [A_CallCenter_UserStateHistory] ee
  93. Where Tb2.UserId = US.Id and ee.OperatorId in (select * from @id) and ee.State=3 and ee.TimeEnter between @dt1 and @dt2 and CAST(CONVERT(CHAR(10), ee.TimeEnter, 108) AS DATETIME) between @tm1 and @tm2
  94. Order by name asc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement