所以我不确定我想要做什么,但是这里有……我有两个存储过程……一个计算一个人每天必须工作的空闲时间,并将记录集放在一个临时表中以提高速度...结果为,字段为日期、人员 ID、小时、分钟。
2013-04-03 10000305 8 30
2013-05-03 10000305 8 30
在他们的工作日内,他们完成了通话,每个通话都有记录的持续时间。我的第二个 SP 计算出他们当天实际工作的时间。结果如下,字段相同,日期,人,小时,分钟。
2013-04-25 10000305 7 20
2013-04-26 10000305 11 7
问题:我必须打电话给两个 SP,然后组织起来。我希望我能把所有东西都放在一个 SP 中,然后有一个如下所示的摘要。问题是第二个 SP 在一天内计算了许多记录以获得其总和,而第一个 SP 只是一天和一个持续时间。当我试图将结果加在一起时,我的结果发疯了,并回购了数百万条记录。有简单的方法还是不可能?
**Date** **User** **Hours** **Minutes** **Actual Hours** **Act Mins**
2013-04-25 10000305 8 30 11 7
这是一个代码片段,两者的工作方式非常相似
CREATE TABLE #TotalUsedTime
(PersonID Int,
[Date] DateTime,
Office Int,
[Hours] Int,
[Minutes] Int)
DECLARE @GetUsedTime NVARCHAR(MAX);
SET @GetUsedTime = N'
Select PersonID, [Date], Office, TotalUsedTime / 3600 AS Hours, (TotalUsedTime % 3600) / 60 AS Minutes
From
( Select PersonID, [Date], Office, DateDiff(Second, Starttime, End) AS TotalUsedTime From Calls Where Completed IS NOT NULL) x '
INSERT #TotalUsedTime EXEC SP_Executesql @GetUsedTime;
Select Cast([Date] as date) Date, #TotalUsedTime.PersonID,
Cast(sum([hours] * 60 + [minutes])/60 as int) As Hours,
Sum([hours] * 60 + [minutes]) - 60 * cast(sum([hours] * 60 + [minutes])/60 as int) As Minutes,
People.Fullname
From #TotalUsedTime
Inner Join People on People.PersonID = #TotalUsedTime.PersonID
Where #TotalUsedTime.[Date] Between @StartDate and @EndDate and Office = @Office
and People.PersonID = @PersonID
Group by cast([DATE] as Date), #TotalUsedTime.PersonID, People.FullName]
End