Sum を HH:MM:SS で計算したい
最初に、HH:MM:SS の datetime 差を計算しています (うまくいきます)
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