Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- declare @id table (id uniqueidentifier)
- insert into @id
- select id from [oktell_settings].[dbo].[A_Users]
- where ParentGroupID = @group
- Select US.Name,Tb2.[CountCall],Tb2.[TIme]
- FROM
- (
- Select Count(id) [CountCall], oktell.dbo.GetTimeFromSecond(sum(Time)) [TIme], [UserId]
- FROM
- (
- select id, datediff(ss,TimeAnswer, TimeStop) [Time], AUserId [UserId]
- FROM [oktell].[dbo].[A_Stat_Connections_1x1]
- where AuserID in (select * from @id)
- and TimeStart between @dt1 and @dt2
- and CAST(CONVERT(CHAR(10), TimeStart, 108) AS DATETIME) between @tm1 and @tm2
- Union All
- select id, datediff(ss,TimeAnswer, TimeStop) [Time], BUserId [UserId]
- FROM [oktell].[dbo].[A_Stat_Connections_1x1]
- where BuserID in (select * from @id)
- and TimeStart between @dt1 and @dt2
- and CAST(CONVERT(CHAR(10), TimeStart, 108) AS DATETIME) between @tm1 and @tm2
- )Tb1
- Group BY [UserId]
- )Tb2,
- [oktell_settings].[dbo].[A_Users] US
- Where Tb2.UserId = US.Id
- Order by name asc
- Я пробовал вот так сделать.
- declare @id table (id uniqueidentifier)
- insert into @id
- select id from [oktell_settings].[dbo].[A_Users]
- where ParentGroupID = @group
- Select US.Name,Tb2.[CountCall],Tb2.[TIme], Tb2.[LengthSec]
- FROM
- (
- Select Count(id) [CountCall], oktell.dbo.GetTimeFromSecond(sum(Time)) [TIme], [LengthSec], [UserId]
- FROM
- (
- select kk.id, datediff(ss,TimeAnswer, kk.TimeStop) [Time], kk.AUserId [UserId] , ee.LengthSec [LengthSec]
- FROM [oktell].[dbo].[A_Stat_Connections_1x1] kk, [A_CallCenter_UserStateHistory] ee
- where kk.AuserID in (select * from @id)
- and kk.TimeStart between @dt1 and @dt2
- and CAST(CONVERT(CHAR(10), kk.TimeStart, 108) AS DATETIME) between @tm1 and @tm2
- 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
- Union All
- select tt.id, datediff(ss,TimeAnswer, tt.TimeStop) [Time], tt.BUserId [UserId] , ww.LengthSec [LengthSec]
- FROM [oktell].[dbo].[A_Stat_Connections_1x1] tt, [A_CallCenter_UserStateHistory] ww
- where tt.BuserID in (select * from @id)
- and tt.TimeStart between @dt1 and @dt2
- and CAST(CONVERT(CHAR(10), tt.TimeStart, 108) AS DATETIME) between @tm1 and @tm2
- 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
- )Tb1
- Group BY [UserId] , [LengthSec]
- )Tb2,
- [oktell_settings].[dbo].[A_Users] US
- Where Tb2.UserId = US.Id
- Order by name asc
- Select US.Name,Tb2.[CountCall],Tb2.[TIme], ee.LengthSec
- FROM
- (
- Select Count(id) [CountCall], oktell.dbo.GetTimeFromSecond(sum(Time)) [TIme], [UserId]
- FROM
- (
- select id, datediff(ss,TimeAnswer, TimeStop) [Time], AUserId [UserId]
- FROM [oktell].[dbo].[A_Stat_Connections_1x1]
- where AuserID in (select * from @id)
- and TimeStart between @dt1 and @dt2
- and CAST(CONVERT(CHAR(10), TimeStart, 108) AS DATETIME) between @tm1 and @tm2
- Union All
- select id, datediff(ss,TimeAnswer, TimeStop) [Time], BUserId [UserId]
- FROM [oktell].[dbo].[A_Stat_Connections_1x1]
- where BuserID in (select * from @id)
- and TimeStart between @dt1 and @dt2
- and CAST(CONVERT(CHAR(10), TimeStart, 108) AS DATETIME) between @tm1 and @tm2
- )Tb1
- Group BY [UserId]
- )Tb2,
- [oktell_settings].[dbo].[A_Users] US, [A_CallCenter_UserStateHistory] ee
- 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
- Order by name asc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement