从上图中可以看出,HHMMSS列是SSRS,其表达式如下:
=CStr(sum(CInt(split(Fields!HHMMSS.Value,":")(0)))
+sum(CInt(split(Fields!HHMMSS.Value,":")(1)))\60)
&":"& CStr(sum(CInt(split(Fields!HHMMSS.Value,":")(1)))
mod 60+sum(CInt(split(Fields!HHMMSS.Value,":")(2)))\60)
&":"& CStr(sum(CInt(split(Fields!HHMMSS.Value,":")(2))) mod 60)
如果列中没有空白,但在没有值或空白时出错,则效果很好。我该如何克服这个问题? 该报告的查询是:
DECLARE @Table TABLE
(
RowID INT IDENTITY(1,1) PRIMARY KEY
, EmpID INT NOT NULL
, StartTime DATETIME NOT NULL DEFAULT('1900/00/00')
, FinishTime DATETIME NOT NULL DEFAULT('1900/00/00')
, JobID INT NULL
, IdleTime INT
)
INSERT INTO @Table(EmpID,StartTime,FinishTime,JobID,IdleTime)
VALUES (100,'2011-09-08 09:00:03.410','2011-09-08 09:55:18.153',12,1)
, (100,'2011-09-08 11:55:03.810','2011-09-08 12:30:18.153',12,-1)
, (101,'2012-10-17 09:19:52.637','2012-10-17 17:19:52.637',15,1)
, (101,'2012-10-17 12:30:52.637','2012-10-17 13:25:52.637',15,-1)
, (103,'2012-10-17 09:00:03.410','2012-10-17 16:19:52.637',20,1)
, (103,'2012-10-17 13:00:03.410','2012-10-17 13:49:52.637',20,-1)
, (104,'2012-10-17 09:00:03.410','2012-10-17 15:19:52.637',54,1)
, (104,'2012-10-17 11:00:03.410','2012-10-17 13:19:52.637',54,-1)
, (105,'2012-10-16 09:00:03.410','2012-10-17 18:19:52.637',56,1)
, (105,'2012-10-17 13:00:03.410','2012-10-17 14:19:52.637',56,-1)
, (106,'2012-10-10 09:00:03.310','2012-10-17 15:19:52.637',10,1)
, (106,'2012-10-17 10:00:03.410','2012-10-17 10:34:52.637',10,-1)
, (106,'2012-10-17 13:00:03.410','2012-10-17 13:35:52.637',10,-1)
, (107,'2012-10-17 09:00:03.410','2012-10-17 15:19:52.637',17,1)
, (108,'2012-10-17 09:00:03.410','2012-10-17 15:19:52.637',19,1)
, (109,'2012-10-17 09:00:03.410','2012-10-17 18:19:52.637',11,1)
, (109,'2012-10-17 10:00:03.410','2012-10-17 10:19:52.637',11,-1)
, (109,'2012-10-17 12:00:03.410','2012-10-17 12:20:52.637',11,-1)
, (109,'2012-10-18 14:00:03.410','2012-10-18 14:20:08.677',11,-1)
, (110,'2012-10-17 09:00:03.410','2012-10-17 15:19:52.637',20,1)
, (101,'2012-10-18 09:19:52.637','2012-10-18 17:19:52.637',15,1)
, (101,'2012-10-18 12:30:52.637','2012-10-18 13:25:52.637',15,-1)
, (103,'2012-10-18 09:00:03.410','2012-10-18 16:19:52.637',20,1)
, (103,'2012-10-18 13:00:03.410','2012-10-18 13:49:52.637',20,-1)
, (104,'2012-10-18 09:00:03.410','2012-10-18 15:19:52.637',54,1)
, (104,'2012-10-18 11:00:03.410','2012-10-18 13:19:52.637',54,-1)
, (105,'2012-10-18 09:00:03.410','2012-10-18 18:19:52.637',56,1)
, (105,'2012-10-18 13:00:03.410','2012-10-18 14:19:52.637',56,-1)
, (106,'2012-10-18 09:00:03.310','2012-10-18 15:19:52.637',100,1)
, (106,'2012-10-18 10:00:03.410','2012-10-18 10:34:52.637',100,-1)
, (106,'2012-10-18 13:00:03.410','2012-10-18 13:35:52.637',10,-1)
, (107,'2012-10-18 09:00:03.410','2012-10-18 15:19:52.637',17,1)
, (108,'2012-10-18 09:00:03.410','2012-10-18 15:19:52.637',19,1)
, (109,'2012-10-18 09:00:03.410','2012-10-18 18:19:52.637',133,1)
, (109,'2012-10-18 10:00:03.410','2012-10-18 10:19:52.637',133,-1)
, (109,'2012-10-18 12:00:03.410','2012-10-18 12:20:52.637',133,-1)
, (109,'2012-10-18 14:00:03.410','2012-10-18 14:20:08.677',133,-1)
, (110,'2012-10-18 09:00:03.410','2012-10-18 15:19:52.637',31,1)
SELECT EmpID
, CONVERT(VARCHAR(10), StartTime, 103) AS [Date]
, CONVERT(VARCHAR(5), StartTime, 108) AS [Time]
, CONVERT(VARCHAR(10), FinishTime, 103) AS Date_Off
, CONVERT(VARCHAR(5), FinishTime, 108) AS Time_Off
, CASE WHEN IdleTime = -1 THEN ''
ELSE CONVERT(VARCHAR(10)
, DATEADD(SECOND, DATEDIFF(SECOND,StartTime,FinishTime),0), 108)END AS HHMMSS
, CASE WHEN IdleTime = -1 THEN CONVERT(VARCHAR(10), DATEADD(SECOND, DATEDIFF(SECOND,StartTime,FinishTime),0), 108)
ELSE '' END AS TrainingTime
FROM @Table
答案 0 :(得分:1)
尝试在以下内容中添加IIF
语句:
=iif(IsNothing(Fields!HHMMSS.Value) OR Fields!HHMMSS.Value = "", "",
CStr(sum(CInt(split(Fields!HHMMSS.Value,":")(0)))
+sum(CInt(split(Fields!HHMMSS.Value,":")(1)))\60)
&":"& CStr(sum(CInt(split(Fields!HHMMSS.Value,":")(1)))
mod 60+sum(CInt(split(Fields!HHMMSS.Value,":")(2)))\60)
&":"& CStr(sum(CInt(split(Fields!HHMMSS.Value,":")(2))) mod 60)
)
<强>更新强>
=iif(Len(Fields!HHMMSS.Value) <= 0, "",
CStr(sum(CInt(split(Fields!HHMMSS.Value,":")(0)))
+sum(CInt(split(Fields!HHMMSS.Value,":")(1)))\60)
&":"& CStr(sum(CInt(split(Fields!HHMMSS.Value,":")(1)))
mod 60+sum(CInt(split(Fields!HHMMSS.Value,":")(2)))\60)
&":"& CStr(sum(CInt(split(Fields!HHMMSS.Value,":")(2))) mod 60)
)
更新2
=iif(Len(Fields!HHMMSS.Value) <= 0, "",
CStr(sum(CInt(split(iif(Len(Fields!HHMMSS.Value) <= 0, "", Fields!HHMMSS.Value),":")(0)))
+sum(CInt(split(iif(Len(Fields!HHMMSS.Value) <= 0, "", Fields!HHMMSS.Value),":")(1)))\60)
&":"& CStr(sum(CInt(split(iif(Len(Fields!HHMMSS.Value) <= 0, "", Fields!HHMMSS.Value),":")(1)))
mod 60+sum(CInt(split(iif(Len(Fields!HHMMSS.Value) <= 0, "", Fields!HHMMSS.Value),":")(2)))\60)
&":"& CStr(sum(CInt(split(iif(Len(Fields!HHMMSS.Value) <= 0, "", Fields!HHMMSS.Value),":")(2))) mod 60)
)