Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Adding up calltimes

Author  Topic 

ninel
Posting Yak Master

141 Posts

Posted - 2005-06-28 : 12:35:04
I have the following table:

Employee Login Logout
1 08:00:00 13:30:00
2 09:25:00 16:25:00
3 13:00:00 19:00:00

How can I add these up to get a total calltime that looks like this:

Emp1: 05:30:00
Emp2: 07:00:00
Emp3: 06:00:00

Thanks,
Ninel

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-06-28 : 12:37:50
select employee, logout-login as diff
from MyTable

Go with the flow & have fun! Else fight the flow
Go to Top of Page

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2005-06-28 : 22:14:43
Your login and logout times are probably character data columns, so slightly modifying Mladen's nicely succinct query, you will probably have to do this:

SELECT employee, CONVERT(char(8), CONVERT(datetime, logout)-CONVERT(datetime, login), 108) AS diff
FROM MyTable

BTW Mladen, I answered this same question on a different forum, but I used DATEDIFF with DATEADD. Your query is a little more efficient, so kudos to you!
Go to Top of Page
   

- Advertisement -