Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 如何对SSRS中的时间数据类型列求和?_Sql Server_Reporting Services_Reporting - Fatal编程技术网

Sql server 如何对SSRS中的时间数据类型列求和?

Sql server 如何对SSRS中的时间数据类型列求和?,sql-server,reporting-services,reporting,Sql Server,Reporting Services,Reporting,我有一张表,在SSRS中看起来像这样: CheckIn CheckOut Hours 9:00:00 10:00:00 1:00:00 9:30:00 10:00:00 0:30:00 9:15:00 10:00:00 0:45:00 所以我只想对小时数列进行汇总,使其看起来像这样 CheckIn CheckOut Hours 9:00:00 10:00:00 1:00:00 9:30:00

我有一张表,在SSRS中看起来像这样:

CheckIn     CheckOut      Hours
9:00:00     10:00:00     1:00:00
9:30:00     10:00:00     0:30:00
9:15:00     10:00:00     0:45:00
所以我只想对小时数列进行汇总,使其看起来像这样

CheckIn     CheckOut      Hours
9:00:00     10:00:00     1:00:00
9:30:00     10:00:00     0:30:00
9:15:00     10:00:00     0:45:00

                       Total Hours
                         2:15:00
我试着用这个表达,但没用

Str(sum(CInt(split(Fields!Hours.Value,":")(0)))
+sum(CInt(split(Fields!Hours.Value,":")(1)))\60)
&":"& CStr(sum(CInt(split(Fields!Hours.Value,":")(1)))
mod 60+sum(CInt(split(Fields!Hours.Value,":")(2)))\60) 
&":"& CStr(sum(CInt(split(Fields!Hours.Value,":")(2))) mod 60)
首先是得到总数()

第二种方法是提取一天,乘以24小时,然后将其相加 到小时值


向报告的“代码”部分添加2个函数:

' I took it here https://www.tek-tips.com/viewthread.cfm?qid=1165634
Public Function TimeStrToSeconds(ByVal strTime As String) As Integer
        Dim strHours As String
        Dim strMinutes As String
        Dim strSeconds As String

        Dim arrTime() As String

        arrTime = strTime.Split(":")

        strHours = arrTime(0)
        strMinutes = arrTime(1)
        strSeconds = arrTime(2)

        TimeStrToSeconds= strHours * 60 * 60
        TimeStrToSeconds+= strMinutes * 60
        TimeStrToSeconds+= strSeconds


End Function

' I took it here http://www.freevbcode.com/ShowCode.asp?ID=638
Public Function Duration(TotalSeconds As Long, UpFormat As _
    Integer) As String

  ' Format = 0, 1, 2
  ' This determines the format of the time to be returned
  ' Type 0: 1d 4h 15m 47s
  ' Type 1: 1 day, 4:15:47
  ' Type 2: 1 day 4hrs 15mins 47secs
  ' Type else: Defaults to type 0

  Dim Seconds
  Dim Minutes
  Dim Hours
  Dim Days
  Dim DayString As String
  Dim HourString As String
  Dim MinuteString As String
  Dim SecondString As String

  Seconds = Int(TotalSeconds Mod 60)
  Minutes = Int(TotalSeconds \ 60 Mod 60)
  Hours = Int(TotalSeconds \ 3600 Mod 24)
  Days = Int(TotalSeconds \ 3600 \ 24)

  Select Case UpFormat
    Case 0
      DayString = "d "
      HourString = "h "
      MinuteString = "m "
      SecondString = "s"
    Case 1
      If Days = 1 Then DayString = " day, " _
      Else: DayString = " days, "
      HourString = ":"
      MinuteString = ":"
      SecondString = ""
    Case 2
      If Days = 1 Then DayString = " day " _
      Else: DayString = " days, "
      If Hours = 1 Then HourString = "hr " _
      Else: HourString = "hrs "
      If Minutes = 1 Then MinuteString = "min " _
      Else: MinuteString = "mins "
      If Seconds = 1 Then SecondString = "sec " _
      Else: SecondString = "secs"
    Case Else
      DayString = "d "
      HourString = "h "
      MinuteString = "m "
      SecondString = "s"
  End Select

  Select Case Days
    Case 0
      Duration = Format(Hours, "0") & HourString & _
            Format(Minutes, "00") & MinuteString & _
             Format(Seconds, "00") & SecondString
    Case Else
      Duration = Days & DayString & _
          Format(Hours, "0") & HourString & Format _
          (Minutes, "00") & MinuteString & _
           Format(Seconds, "00") & SecondString
    End Select

End Function
你的总数:

=Code.Duration(Sum(Code.TimeStrToSeconds(Fields!Hours.Value)),1)

您是否尝试过TimeSpan.FromTicks(总和(字段!小时.值))@ᴇᴛᴀʟ这很完美,但它只能显示小时数吗?因为在我的报告中,我的时间加起来是“37:34”,显示的是“1.13:34:00”,也就是一天13小时那么你的分钟数呢?比如说02:50+23:50?根据表达式,它不会延续额外的分钟数。
=Code.Duration(Sum(Code.TimeStrToSeconds(Fields!Hours.Value)),1)