0

在 SSRS 中,我需要确定驱动程序在用户指​​定的日期之间登录系统的次数 - 我已经显示了报告[Driver] "LoggedOn at" [TimeOn] "Logged off at" [TimeOff] "for a duration of" [TimeOff-TimeOn](比它更多,但就是这样)。

生成的报告如下所示并且工作正常:

David Niven logged on at .... for a duration of 3 hours

John Jones logged on at ... for a duration of 7 hours

David Niven logged on at ... for a duration of 5 hours

David Niven logged on at ... for a duration of 2 hours

Paul Newman logged on at .... for a duration of 3 hours etc etc

我需要做的是提供一个摘要 - 即在用户指定的日期之间

David Niven logged on 3 times for a total duration of 10 hours
John Jones logged on 1 time for a total duarion of 7 hours
Paul Newman logged on 1 time for a total duartion of 3 hours

我可以使用表达式来添加每个驱动程序在 SSRS 2008 中登录的次数和登录时间吗?- 如果是这样,如何 - 如果需要,可以给出我的查询的更具体示例......非常感谢提前

4

2 回答 2

0

您可以使用两个不同的查询,只使用分组和子查询:

DECLARE @driverInfo TABLE
(
    Name varchar(50),
    TimeOn datetime,
    TimeOff datetime
)

INSERT INTO @driverInfo
SELECT 'David Niven', '2013-07-23 09:00', '2013-07-23 12:00'
UNION ALL SELECT 'John Jones', '2013-07-23 09:00', '2013-07-23 16:00'
UNION ALL SELECT 'David Niven', '2013-07-23 13:00', '2013-07-23 18:00'
UNION ALL SELECT 'David Niven', '2013-07-24 09:00', '2013-07-24 11:00'
UNION ALL SELECT 'Paul Newman', '2013-07-23 09:00', '2013-07-23 12:00'

-- used for first data set
SELECT *, DATEDIFF(hour, TimeOn, TimeOff) AS [TotalHours]
FROM @driverInfo

-- used for second data set
SELECT Name, COUNT(*), SUM(TotalHours)
FROM (
    SELECT Name, DATEDIFF(hour, TimeOn, TimeOff) AS [TotalHours]
    FROM @driverInfo
) S
GROUP BY S.Name
于 2013-07-24T06:07:09.513 回答
0

如果您想在与详细信息值相同的数据集的报表级别执行此操作,您可以将这样的表达式添加到组页眉/页脚:

=Fields!Driver.Value
  & " logged on "
  & CountRows()
  & " times for a total duration of "
  & Sum(DateDiff(DateInterval.Hour, Fields!TimeOn.Value, Fields!TimeOff.Value))
  & " hours"

CountRows只需给出组中的行数,即登录次数,您可以DateDiff将组中每一行的值相加得到总小时数。

于 2013-07-24T09:23:04.550 回答