--- Sanjeev <sanjeev.atvankar@gmail.comwrote:
Quote:
Table def :
Create Table Callbycall(
Agent int,
Start_Time datetime,
End_Time datetime
)
>
and required output as follows
>
Agent Start_Time End_Time
Idle_Time(derived column)
================================================== =========
194 2008-05-30 10:19:00 2008-05-30 10:23:06.000 15:54
194 2008-05-30 10:39:00 2008-05-30 10:41:59.000 02:01
194 2008-05-30 10:44:00 2008-05-30 11:11:45.000 05:15
194 2008-05-30 11:17:00 2008-05-30 11:22:19.000 23:41
194 2008-05-30 11:46:00 2008-05-30 12:55:56.000 00:00
200 2008-05-30 13:02:00 2008-05-30 13:56:34.000 39:26
200 2008-05-30 14:36:00 2008-05-30 14:36:00.000 64:00
200 2008-05-30 15:40:00 2008-05-30 15:58:20.000 .....
200 2008-05-30 13:02:00 2008-05-30 13:56:34.000 00:00
.................
.................
.................
380 2008-05-30 13:02:00 2008-05-30 13:56:34.000 39:26
380 2008-05-30 14:36:00 2008-05-30 14:36:00.000 64:00
380 2008-05-30 15:40:00 2008-05-30 15:58:20.000 .....
380 2008-05-30 13:02:00 2008-05-30 13:56:34.000 00:00
|
The first issue is calculating the seconds.
SELECT *,
DATEDIFF(second, A.End_Time,
(SELECT MIN(Start_Time)
FROM Callbycall as B
WHERE A.Agent = B.Agent
AND A.Start_Time < B.End_Time)) as ElapsedSecond
FROM Callbycall as A
One way to format the time expression, which you should be able to
adapt to your needs:
declare @i int
set @i = 12345
SELECT convert(char(8), dateadd(second, @i, 0), 114)
--------
03:25:45
Roy Harvey
Beacon Falls, CT