Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL .NET SQL-Server , +
I am creating a report and have a field in my database called "Duration" which is represented in time format. I am trying to calculate the total duration by adding the durations together using "[Sum(Duration)]". I keep however getting "#ERROR" when I do this.
 
If anyone could help me out I would be very grateful!
Posted 11-Jul-13 6:07am
Comments
ryanb31 at 11-Jul-13 13:05pm
   
You need to click on Improve question and post the relevant code so we can see what you have so far.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

When you are trying to get sum of a TimeFormat, you should sum the minutes.
Try executing this query in your query window
Declare @TempTable Table(TimeValue VarChar(20))
 

Insert Into @TempTable Values('12:00 PM')
Insert Into @TempTable Values('1:00 PM')
Insert Into @TempTable Values('10:00 AM')
 

Select Sum(DateDiff(Minute, 0, TimeValue)) As TotalDuration
       From   @TempTable 
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 240
2 DamithSL 200
3 Raul Iloc 185
4 Richard MacCutchan 175
0 OriginalGriff 5,130
1 DamithSL 4,197
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 11 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100