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
 SQL Server Development (2000)
 Time Calculation with smalldatetime

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-10-26 : 08:50:12
Walter writes "Hello,
I'm storing time values in a table using smalldatetime. Each record represents a working task from a employee. Table is like:

CustomerID(int), ProcessID(int), UsedTime(smalldatetime)
1000, 40, 03:15:00

At the end of the month i need the sum of UsedTime for every CustomerID. But SUM(UsedTime) doesn't work. How can i get the Total UsedTime of every customer, what have i to do ? I'm really in a panic, i can't find a way to do this. Do you have a solution ? Rgds Walter"

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-10-26 : 09:24:19
there probably is an easier way...

declare @table table (UsedTime datetime)
insert into @table
select '01/01/1900 03:15' union all
select '01/01/1900 04:20' union all
select '01/01/1900 01:05' union all
select '01/01/1900 06:35'

select sum(datepart(hh, UsedTime)) + cast(sum(datepart(mi, UsedTime)) as decimal(9,2))/60
from @table


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

- Advertisement -