Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.43 KB | None | 0 0
  1. SELECT CONVERT(varchar, callstart, 120) as CallStartDateTime, ConnTime, RingTime, rtrim(Calling_id) as Calling_id, rtrim(CallNumber) as CallNumber,
  2. CAST(CASE
  3.         WHEN Direction = 'I' THEN 'входящий'
  4.         WHEN (IsIntern = 1) and (LEN(CallNumber)<6) THEN 'внутренний'
  5.         WHEN (IsIntern = 1) and (LEN(CallNumber)>=6) THEN 'твиннинг'
  6.         WHEN ISNULL(Calling_id,'')='' THEN 'твиннинг'
  7.         ELSE 'исходящий'
  8.      END AS varchar) as Direction
  9. FROM STR_SMDR as t0  
  10. WHERE t0.CallStart BETWEEN '2017-08-10 00:00:00.000' AND '2017-08-21 23:59:59.999'
  11. AND  (
  12.       ((t0.CallNumber IN
  13.             ( 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 )
  14.       ) AND (SUBSTRING(ISNULL(t0.Party1Device, ''), 1, 1)<>'E' OR (SUBSTRING(ISNULL(t0.Party1Device, ''), 2, 4) = t0.Calling_id)))
  15.       OR
  16.       ((SUBSTRING(ISNULL(t0.Party1Device, ''), 2, 4) IN
  17.             ( 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 )
  18.       ) AND (SUBSTRING(ISNULL(t0.Party1Device, ''), 1, 1)='E' AND (SUBSTRING(ISNULL(t0.Party1Device, ''), 2, 4) <> t0.Calling_id)))
  19.      )
  20. ORDER BY callstart, callID, SmdrId
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement