SQLTeam.com | Weblogs | Forums

Total of muliple rows with primary key value


#1

Dear All,

I am trying following query and getting following output.
I want the desired output.
How to sum of total with the primary key value ?

Query:

SELECT Emp_ID,cast(sum(datediff(second,0,Short_Extra_Hour_days))/3600 as varchar(12)) + ':' +
right('0' + cast(sum(datediff(second,0,Short_Extra_Hour_days))/60%60 as varchar(2)),2) AS Total
FROM [HRMS_TEST].[dbo].[M_SHORT_EXTRA_HOURS]
group by Emp_ID,Short_Extra_Hour_Type

Output:
EMPID TOTAL
10 2:00
10 9:30
9 3:30

Desired Output:
EMPID TOTAL
10 11:30
9 3:30

Thanks,
Harish Patil


#2

What is in the column Short_Extra_Hour_Type


#3

Yeah, remove the Short_Extra_Hour_Type from the GROUPing; just:
group by Emp_ID