SSRS 2008 - 计算返回结果的实例

时间:2013-07-24 05:24:26

标签: reporting-services count ssrs-2008

在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中登录的次数以及持续时间吗? - 如果是这样,如何 - 如果需要,可以提供我的查询的更具体的例子......许多人提前感谢

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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值相加,得到总小时数。