Solved

# SQL add time - convert

Posted on 2013-01-08
276 Views
I need to convert minutes to hours and then group by attendee. I'm learning SQL but this one is stumping me. Any help would be greatly appreciated. I know, I need to remove the first column, I'm just frustrated and thought I would copy the code I had before I loose it. : )  Thanks again for the help.

Here is the code

SELECT     SUM(Time) AS TotalMinutes, AttendeeName, TotalNew
FROM         (SELECT     AttendeeName, Time, CONVERT(VARCHAR, Time / 60) + ':' + RIGHT('00' + CONVERT(VARCHAR, Time % 60), 2) AS TotalNew
FROM          OMUCourse AS OMUCourse_1) AS OMUCourse
GROUP BY AttendeeName, TotalNew

Current Results:

10      Dan Mahoney      0:10
15      Bryan Smith      0:15
15      Dan Mahoney      0:15
20      Bryan Smith      0:20
20      Bill Wright      0:20
20      Dan Mahoney      0:20
20      Ms Wendy Jordan      0:20
25      Dan Mahoney      0:25
25      Ms Wendy Jordan      0:25

Need These Results:

Dan Mahoney      1:05
Bryan Smith      0:35
Bill Wright      0:20
Ms Wendy Jordan      0:45
0
Question by:Vidalle
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions

LVL 37

Expert Comment

ID: 38757694
would the third column always be less than 1 hour?
what is the data type of the third column?
0

Author Comment

ID: 38757722
Thanks, it will go over 1 hour.
0

LVL 39

Accepted Solution

Pratima Pharande earned 500 total points
ID: 38757811
does Time column contain data in int which are minutes ?

then you can try this

Select AttendeeName ,
CAST(Sum(Time)/ 60 AS VARCHAR(10)) + '.'
+ RIGHT('0' + CAST(Sum(Time) % 60 AS VARCHAR(2)), 2)
as TOtal_new
from OMUCourse
Group by AttendeeName
0

Expert Comment

ID: 38757901
for example : 65 minutes  result would like 01:05:00

0

Author Closing Comment

ID: 38758463
This is exactly what I needed. Thanks for writing it out using my code. Since  I'm still learning, it made all the difference. Thanks again!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Title # Comments Views Activity
How can I find this data? 3 41
denied execute as 13 57
T-SQL: problem comparing datetime 4 77
SQL Server How to create a List of Values comma separated from a TABLE? 4 43
Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
###### Suggested Courses
Course of the Month6 days, 19 hours left to enroll

#### 732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.