Calculate the SUM of the Column which has Time DataType:

Posted by thevan on Stack Overflow See other posts from Stack Overflow or by thevan
Published on 2012-05-31T09:30:47Z Indexed on 2012/05/31 10:40 UTC
Read the original article Hit count: 227

Filed under:
|
|
|
|

I want to calculate the Sum of the Field which has Time DataType.

My Table is Below:

  TableA:

            TotalTime
          -------------
             12:18:00
             12:18:00

Here I want to sum the two time fields. I tried the below Query

   SELECT CAST(
              DATEADD(MS, SUM(DATEDIFF(MS, '00:00:00.000', 
                CONVERT(TIME, TotalTime))), '00:00:00.000'
               ) AS TOTALTIME) 
    FROM [TableA]

But it gives the Output as

            TOTALTIME
        -----------------
         00:36:00.0000000

But My Desired Output would be like below:

            TOTALTIME
        -----------------
            24:36:00

How to get this Output?

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server-2008