Addtion of time(How to sum the time(in nvarchar format) using Sql server 2005) [Resolved]

Posted by Ravianand under Sql Server on 6/13/2012 | Points: 10 | Views : 2147 | Status : [Member] | Replies : 5
How to sum the time(in nvarchar format) using Sql server 2005
Ex: 10:50 (hh:mm) i have multiple rows of time in nvarchar format using aggregate function to sum up the values.

Regards,
Ravi



Responses

Posted by: CGN007 on: 6/13/2012 [Member] Silver | Points: 50

Up
0
Down

Resolved
SELECT	STUFF(CONVERT(CHAR(8), DATEADD(SECOND, theSeconds, '19000101'), 8), 1, 2, CAST(theSeconds / 3600 AS VARCHAR(12)))

FROM (
SELECT ABS(SUM(DATEDIFF(SECOND, '00:00', time))) AS theSeconds
FROM timeadd
) AS t


Ravianand, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 6/13/2012 [Member] Silver | Points: 25

Up
0
Down
Please share your table schema..
Is that column stores time only in nvarchar format?OR it a datetime in nvarchar?

Ravianand, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ravianand on: 6/13/2012 [Member] Starter | Points: 25

Up
0
Down
columns stores time as nvarchar format only.

Regards,
Ravi

Ravianand, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 6/13/2012 [Member] Silver | Points: 25

Up
0
Down
Hope that query works fine for you...
Please let me know,if there any error.!!

Ravianand, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 6/23/2012 [Member] Silver | Points: 25

Up
0
Down
Thanks man...

Ravianand, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response