Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT CONVERT(varchar, callstart, 120) as CallStartDateTime, ConnTime, RingTime, rtrim(Calling_id) as Calling_id, rtrim(CallNumber) as CallNumber,
- CAST(CASE
- WHEN Direction = 'I' THEN 'входящий'
- WHEN (IsIntern = 1) and (LEN(CallNumber)<6) THEN 'внутренний'
- WHEN (IsIntern = 1) and (LEN(CallNumber)>=6) THEN 'твиннинг'
- WHEN ISNULL(Calling_id,'')='' THEN 'твиннинг'
- ELSE 'исходящий'
- END AS varchar) as Direction
- FROM STR_SMDR as t0
- WHERE t0.CallStart BETWEEN '2017-08-10 00:00:00.000' AND '2017-08-21 23:59:59.999'
- AND (
- ((t0.CallNumber IN
- ( SELECT user_profile FROM PacketsTelephony.dbo.[Authentication] JOIN PacketsTelephony.dbo.[ourstations] ON st_id = op_pref WHERE user_profile is not null and st_id = SrcTbl AND [id_customer]=3279784 )
- ) AND (SUBSTRING(ISNULL(t0.Party1Device, ''), 1, 1)<>'E' OR (SUBSTRING(ISNULL(t0.Party1Device, ''), 2, 4) = t0.Calling_id)))
- OR
- ((SUBSTRING(ISNULL(t0.Party1Device, ''), 2, 4) IN
- ( SELECT user_profile FROM PacketsTelephony.dbo.[Authentication] JOIN PacketsTelephony.dbo.[ourstations] ON st_id = op_pref WHERE user_profile is not null and st_id = SrcTbl AND [id_customer]=3279784 )
- ) AND (SUBSTRING(ISNULL(t0.Party1Device, ''), 1, 1)='E' AND (SUBSTRING(ISNULL(t0.Party1Device, ''), 2, 4) <> t0.Calling_id)))
- )
- ORDER BY callstart, callID, SmdrId
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement