Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I have a column which stores hours & minutes (HH:MM) as computed column. each data entry would be similar to this format: 1:45 (represents 1 hour and 45 minutes).I need to return the total no of hours from this field using SUM but need to convert the time representation to a decimal value. So for example:1.45 (1 hour and 45 minutes)3.20 (3 hours and 20 minutes)2.40 (2 hours and 40 minutes)Any help appreciated.
malpashaa
Constraint Violating Yak Guru
264 Posts
Posted - 2010-12-05 : 03:30:57
Try something like this:
DECLARE @SomeTable TABLE( hours_and_minutes VARCHAR(5) NOT NULL);INSERT INTO @SomeTable(hours_and_minutes) VALUES('1:45'), ('3:20'), ('2:40');SELECT SUM(DATEDIFF(MINUTE, 0, hours_and_minutes)) / 60.0 FROM @SomeTable