我想要计算总和HH:MM:SS
首先我正在计算日期时间差在HH:MM:SS(效果很好)
Select *
Into #_TicketType
From (
Select *,
convert(varchar(5), DateDiff(s, [Start Date] , [End Date] )/3600)
+ ':'
+ convert(varchar(5),DateDiff(s, [Start Date] , [End Date])%3600/60)
+ ':'
+ convert(varchar(5),(DateDiff(s,[Start Date] , [End Date])%60)) as [Ticket Type Time]
,
convert(varchar(5),DateDiff(s, [Ticket Open Time] , [Ticket Closed Time] )/3600)
+ ':'
+ convert(varchar(5),DateDiff(s,[Ticket Open Time] , [Ticket Closed Time])%3600/60)
+ ':'
+ convert(varchar(5),(DateDiff(s,[Ticket Open Time] , [Ticket Closed Time])%60))[Total Call Time]
FROM CTE
)_A
列[Start Date] , [End Date],[Ticket Open Time] , [Ticket Closed Time]
类型的DateTime
另外我想计算HH它总和:MM:SS
我的查询: -
Select Distinct ATM,
CAST (
(SUM (datepart(hh, convert (varchar, [Ticket Type Time], 108)))
+ (sum (datepart(mi, convert (varchar, [Ticket Type Time], 108)))/60) )
AS VARCHAR(2))
+ ':'
+ CAST (
sum( datepart(mi, convert (varchar, [Ticket Type Time], 108)))
- 60
* (sum(datepart(mi, convert (varchar, [Ticket Type Time], 108)))/60)
as VARCHAR(2))
+ ':'
+ CAST (
sum( datepart(ss, convert (varchar, [Ticket Type Time], 108)))
- 60
* (sum( datepart(SS, convert (varchar, [Ticket Type Time], 108)))/60)
as VARCHAR(2))
From #_TicketType Group By ATM
它给我的错误
**Msg 241, Level 16, State 1, Line 67
Conversion failed when converting date and/or time from character string.**
DATEBASE SQL SERVER 2008