Click here to Skip to main content
15,922,584 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hours | Minutes
16 | 30
39 | 45
26 | 0
15 | 30


How do I get total this 2 columns in one column?

Answer should be 97:45

What I have tried:

What would be best. Used Sum() function.
Posted
Updated 20-Aug-20 1:24am

1 solution

Convert the hours to minutes, then add them together.
Then convert the summed value to hours and minutes as a string:
SQL
SELECT CAST(TotMins / 60 AS NVARCHAR) + 
       ':' + 
       CAST(TotMins % 60 AS NVARCHAR) 
FROM (SELECT SUM((Hours * 60) + Minutes) AS TotMins 
      FROM MyTable) t
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900