Question

Our company logs incoming phone calls to different agents in a VarChar field in an SQL table. This field is the EventLog.

Hence, Select EventLog From DB Where CallID = 'Long_String_of_Numbers' yields the following in one LONG line:

21:02:10: Initializing 21:02:10: Offering 21:02:10: ANI:  5551234567 21:02:10: DNIS:  1032 21:02:10: Call answered 21:02:10: Call from: 5551234567 21:02:12: Offering 21:02:12: Entered Workgroup Clients 21:02:20: ACD - Wait Agent 21:02:20: ACD - Wait Agent 21:02:20: ACD - Wait Agent 21:02:20: ACD call waiting for agent 21:05:47: ACD interaction assigned to arnoldSW 21:05:47: ACD call waiting for agent 21:05:47: ACD - Alerting: arnoldSW 21:05:48: Offering 21:05:48: Sent to user arnoldSW 21:05:48: Alerting 21:05:48: Sent to station WOLF1 21:05:51: Connected 21:05:51: ACD interaction connected to arnoldSW 21:05:51: ACD - Assigned: arnoldSW 21:15:34: Sent to station ABC 21:16:42: Held 21:17:19: Connected 21:17:19: Sent to user northSK 21:20:04: Disconnected [Local Hang Up]

For simplicity, here's the formatted string in one line:

21:02:10: Initializing 
21:02:10: Offering 
21:02:10: ANI:  5551234567 
21:02:10: DNIS:  1032 
21:02:10: Call answered 
21:02:10: Call from: 5551234567 
21:02:12: Offering 
21:02:12: Entered Workgroup Clients 
21:02:20: ACD - Wait Agent 
21:02:20: ACD - Wait Agent 
21:02:20: ACD - Wait Agent 
21:02:20: ACD call waiting for agent 
21:05:47: ACD interaction assigned to arnoldSW 
21:05:47: ACD call waiting for agent 
21:05:47: ACD - Alerting: arnoldSW 
21:05:48: Offering 
21:05:48: Sent to user arnoldSW 
21:05:48: Alerting 
21:05:48: Sent to station WOLF1 
21:05:51: Connected 
21:05:51: ACD interaction connected to arnoldSW 
21:05:51: ACD - Assigned: arnoldSW                 // Duration From HERE ...
21:15:34: Sent to station ABC 
21:16:42: Held 
21:17:19: Connected 
21:17:19: Sent to user northSK 
21:20:04: Disconnected [Local Hang Up]             // ... To Here

What is the most efficient way to calculate the duration in minutes between ACD - Assigned and Disconnected? (NOTE: The number of steps recorded before, between and after these events varies, and I need to do this for at least 19,000 calls. Hence, an efficient way to build statistics.)

Was it helpful?

Solution

So many questions, like this one, boil down to poor schema. Nevertheless, if you can't alter it then you can do something similar to the below. It searches for the field name, backs up the appropriate number of characters, and converts the time to an actual time data type so that it can then use DATEDIFF to calculate the # of seconds. I left it at seconds because you didn't specify how you want to round to minutes but the conversion to minutes is simple enough.

DECLARE @test varchar(2048)

SET @test = '21:02:10: Initializing 21:02:10: Offering 21:02:10: ANI:  5551234567 21:02:10: DNIS:  1032 21:02:10: Call answered 21:02:10: Call from: 5551234567 21:02:12: Offering 21:02:12: Entered Workgroup Clients 21:02:20: ACD - Wait Agent 21:02:20: ACD - Wait Agent 21:02:20: ACD - Wait Agent 21:02:20: ACD call waiting for agent 21:05:47: ACD interaction assigned to arnoldSW 21:05:47: ACD call waiting for agent 21:05:47: ACD - Alerting: arnoldSW 21:05:48: Offering 21:05:48: Sent to user arnoldSW 21:05:48: Alerting 21:05:48: Sent to station WOLF1 21:05:51: Connected 21:05:51: ACD interaction connected to arnoldSW 21:05:51: ACD - Assigned: arnoldSW 21:15:34: Sent to station ABC 21:16:42: Held 21:17:19: Connected 21:17:19: Sent to user northSK 21:20:04: Disconnected [Local Hang Up]'

SELECT
    CAST(SUBSTRING(@test, PATINDEX('%ACD - Assigned:%', @test) - 10, 8) AS time) AS AssignedTime,
    CAST(SUBSTRING(@test, PATINDEX('%Disconnected%', @test) - 10, 8) AS time) AS DisconnectTime,
    DATEDIFF(second, 
        CAST(SUBSTRING(@test, PATINDEX('%ACD - Assigned:%', @test) - 10, 8) AS time),
        CAST(SUBSTRING(@test, PATINDEX('%Disconnected%', @test) - 10, 8) AS time)) AS SecondsElapsed
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top