您好我正在为考勤管理系统创建RDLC报告。在我的报告中,我想要总计WorkedHours
。
我想要这个输出
EmployeeId EmployeeName WorkedHours
1 ABC 04:00:25
2 XYZ 07:23:01
3 PQR 11:02:15
所以我想在RDLC报告结尾处显示所有3名员工的总数。
像总计:22:25:41答案 0 :(得分:0)
试试这个
select EmpId,In_duration,out_duration,
datediff(mi,in_duration,out_duration) as Diff_mins
from table
DateDiff中的第一个参数是mi(分钟)。如果你在文档中查找dateDiff,你会看到其他选项。以下示例显示了作为字符串的小时,分钟和秒的差异。
select
LTRIM(STR(DATEDIFF(mi,in_duration,out_duration) /60))+':'+
LTRIM(STR(DATEDIFF(mi,in_duration,out_duration) %60))+':'+
LTRIM(STR(DATEDIFF(ss,in_duration,out_duration) -
(DATEDIFF(ss,in_duration,out_duration)/60)*60))
as diff
答案 1 :(得分:0)
declare @T table
(
EmployeeId int,
EmployeeName varchar(10),
WorkedHours varchar(8)
)
insert into @T
select 1, 'ABC', '04:00:02' union all
select 2, 'XYZ', '07:23:01' union all
select 3, 'PQR', '11:02:15'
select right(100+T2.hh, 2)+':'+right(100+T2.mm, 2)+':'+right(100+T2.ss, 2) as TotalHours
from (
select dateadd(second, sum(datediff(second, 0, cast(WorkedHours as datetime))), 0) as WorkedSum
from @T
) as T1
cross apply (select datediff(hour, 0, T1.WorkedSum) as hh,
datepart(minute, T1.WorkedSum) as mm,
datepart(second, T1.WorkedSum) as ss) as T2
datediff
计算小时数datepart
获取分钟和秒数right(100+T...)
在值之前添加0
。 cross apply ...
部分不是必需的。我补充说,以使代码更清晰。如果您愿意,可以直接在字段列表中使用cross apply
中的表达式。