将列时间拆分为2(时间,日期)

时间:2016-02-02 18:13:13

标签: sql sql-server

如何重新格式化此代码以将结果列时间拆分为2(时间,日期)

SELECT 
DATEADD(mi, DATEDIFF(mi, 0, DATEADD(s, 2, dbo.roundtime
       (CallStartTime, 1
       ))), 0) AS [Time], COUNT(DISTINCT [CallID]) AS [Sum of Calls]
FROM [Database].[dbo].[table]
WHERE CallStartTime BETWEEN '8/2/2015' AND '2/2/2016'
      AND
      CompanyID NOT IN
                       (718, 722, 1769, 1886, 2518, 2519, 2533, 2544, 2766, 2877, 3603, 3604, 4785, 5674, 5675, 5676, 5677, 5678, 5679, 5680, 5681,
                       5682, 5683, 5684, 5685, 5686, 5687, 5688, 5689, 5690, 5691, 5692, 9021, 9492, 9884, 4785, 11059, 11777, 11779, 13194
                       )

enter image description here

1 个答案:

答案 0 :(得分:0)

转换是你的朋友:

select convert(char(10), getdate(), 120) dateComponent
, convert(char(5), getdate(), 108) timeComponent

编辑从此处开始:

对于你的问题:

select convert(char(10), time, 120) dateComponent
, convert(char(5), time, 108) timeComponent
, "sum of calls"
from 
(sql from the question goes here) temp