我想在 HH:MM:SS 中计算 Sum
首先,我正在计算 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.**
数据库 SQL 服务器 2008