Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi I'm looking for a way to calculate the sum of a datetime column, i've searched through the forum, but nothing turned up which i could modify a little to meet my needs...my table dif looks a little like this.id ident.usrid varcharusage datetimeid usrid usage1 28780116 01:34:002 28780116 00:06:023 28780805 00:00:104 28780116 00:00:15I would then like to return a result for 28780116. and in the format 00:00:00, the result for 28780116 should look like this 01:40:17 Is this possible ?select * from table sum(???) where usrid='28780116'Any help would be much appreciated.Best regardsTaz
robvolk
Most Valuable Yak
15732 Posts
Posted - 2004-12-07 : 08:14:25
If all of your date values are time only, this should work:SELECT DateAdd(s, Sum(DateDiff(s, 0, usage)), 0) AS TotalTime FROM myTable WHERE usrid='28780116'You'll get a date portion as well, and if the total exceeds 24 hours you'll need to work on it a little more to get the right display.
TazMania
Yak Posting Veteran
63 Posts
Posted - 2004-12-07 : 08:42:21
Hi robvolk.Thank you.. it works like a charm Best regardsTaz