Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SUM total time in SQL Server [duplicate]

I have a problem with the SUM operator in SQL Server. When I write this query:

SELECT StudentID, StudentName, SUM(time) as 'TotalTime' 
FROM WorkNote
GROUP BY StudentID, StudentName

I get this error:

Operand data type time is invalid for sum operator.

Is there some other method for SUM or to calculate the total times from the records?

In my WorkNote table, the type of column time is Time(7), and I want to SUM all (total) times for every student.

like image 920
Anna Dino Avatar asked Oct 23 '13 07:10

Anna Dino


People also ask

How do you SUM duplicate values in SQL?

How do I sum the same records in SQL? The DISTINCT modifier instructs the SUM() function to calculate the total of distinct values, which means the duplicates are eliminated. The ALL modifier allows the SUM() function to return the sum of all values including duplicates.

How do you SUM HH MM SS in SQL Server?

WITH Summed AS ( SELECT S.name , SUM(DATEDIFF(SECOND, T. create_date, T. modify_date)) AS Seconds FROM sys. tables T INNER JOIN sys.


1 Answers

if the time in hh/mm/ss then ::

SELECT studentid,studentname,
         DATEADD(ms, SUM(DATEDIFF(ms, '00:00:00.000', mytime)), '00:00:00.000') as time
    FROM
         worknote
like image 85
vhadalgi Avatar answered Sep 22 '22 13:09

vhadalgi