- UPDATE top(1) CallRecords
- SET Guid = OtherTable.guid
- FROM (SELECT Top(1)
- ct.[RowGuid] as guid
- ,ct.[StartDateTime] as datetime
- ,ct.[Duration] as duration
- --,ex.Extension as agentid
- ,case when ex.Extension like '%T%' then ag.AgentID else ex.Extension end as agentid
- --,ag.AgentID as ag
- --,ex.Description as agentname
- ,out.Number as ani
- FROM [CTSDevices].[dbo].[Calls] as ct
- inner join [CTSDevices].[dbo].callextensions as ex
- on ct.CallExtensionID=ex.ID
- inner join [CTSDevices].[dbo].CallACDAgents ag
- on ct.CallACDAgentID=ag.ID
- inner join [CTSDevices].[dbo].CallOutsidePartyNumbers as out
- on ct.CallOutsidePartyNumberID=out.ID
- --where ex.Extension=callrec.ExtentionID
- -- where out.Number=callrec.CallerId
- where ex.Extension not like '%#%'
- order by ct.ID desc
- ) AS OtherTable
- WHERE (
- CallRecords.ExtentionID = OtherTable.agentid) and CallRecords.CallerId like OtherTable.ani and CallRecords.Guid is null
Recent Pastes