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.
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.
WITH Summed AS ( SELECT S.name , SUM(DATEDIFF(SECOND, T. create_date, T. modify_date)) AS Seconds FROM sys. tables T INNER JOIN sys.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With