Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Time Duration Addition


Time Duration Addition

Author
Message
Anirudh
Anirudh
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 59
Hello,

Was wondering - if someone has any suggestions - whereby which we can add time durations.

Example: The Table looks like this:

Date No. of Hours Worked Type
01/02/2009 10.29 1
01/03/2009 2.67 2
and so on ...

Now - if we were to query the total no. of hours worked for Type 1 for the Month of January 2009 - any suggestions !!!

Their is a way about going about it - by converting it into varchar, then splitting the : and taking the summation of the hours and the sumation of the minutes - which is to be converted again into hours and minute ...

Any simpler suggestion pls !!! ...
Jack Corbett
  Jack Corbett
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12870 Visits: 14863
Why can't you just use SUM? The data you show looks like it is hours and decimal part of the hour (2.67), not seconds so a SUM should work. Do you want to show hours and minutes instead of hours and decimal part of the hour (2.67)?



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Bruce W Cassidy
Bruce W Cassidy
SSC Eights!
SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)

Group: General Forum Members
Points: 885 Visits: 1033
You can try casting to datetime, then using datediff() to calculate the number of seconds.
andrewd.smith
andrewd.smith
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1316 Visits: 3232
Either format the total hours worked in front end, or if this is not applicable something like:

SELECT CONVERT(varchar(10), CONVERT(int, SUM(HoursWorked))) + ':' 
+ RIGHT('0' + CONVERT(varchar(2), CONVERT(int, FLOOR(60.0 * SUM(HoursWorked) + 0.5)) % 60), 2)
FROM ...



If the sum of the hours worked was guaranteed to be less than 24 hours then you could use the following, but I don't think this will work for you in this case.

SELECT CONVERT(varchar(5), DATEADD(minute, CONVERT(int, FLOOR(60.0 * SUM(HoursWorked) + 0.5)), 0), 108)


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search