We help IT Professionals succeed at work.
Get Started

How to aggregate hours based on service type and date?

195 Views
Last Modified: 2015-02-26
Hi,

I would like to modify the query below so that it aggregates the DailyHours based on service type and Entry Day.  I would like the results for 1/21 to be one row and looks like:

Ruben       De Luna      01/21/2015      150.00      2      14970            0      2015-01-21 13:15:00.000

My current MS SQL server query is below:

            SELECT
            (U.FirstName + ISNULL(U.MiddleName, ' ')) AS FirstName,  
            U.LastName,
            CONVERT(VARCHAR(15), N.StartTime, 101) AS EntryDay,
            SUM(N.Duration) AS DailyHours,
            N.ServiceType,
            N.UserId AS StudentId,
            '',
            0,
            N.StartTime,
            N.Subject
            FROM [Notes_Student] AS N WITH (NOLOCK)
            INNER JOIN [User] AS U WITH (NOLOCK) ON N.UserId = U.Id AND U.Id <> 725
            WHERE  (N.LocationId = 379 AND N.[Attendance] = 1 AND N.UserId = 14970 AND N.StartTime BETWEEN '1/1/2015' AND '1/31/2015')
            GROUP BY U.LastName, U.FirstName, U.MiddleName, N.ServiceType, N.Subject, CONVERT(VARCHAR(15), N.StartTime, 101), N.StartTime, N.UserId;
Capture3.JPG
Comment
Watch Question
Director, Practice Manager and Computing Consultant
Awarded 2014
Top Expert 2014
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE