我在 sql server 2012 中编写了一个数据透视查询。它工作正常,它显示了行下的用户名结果和列下的生产时间总和(以秒为单位)。但我需要将秒数拆分为小时:分钟格式。请帮我查询。
declare @empid nvarchar(20), @fromdate date, @todate date, @cols nvarchar(max), @query AS VARCHAR(MAX), @dt varchar(20), @dt1 varchar(20)
set @empid = 'EC0100'
set @fromdate = '10/01/13'
set @todate = '10/31/13'
set @dt='Exceptions'
set @dt1='Tech Issues'
select @cols = STUFF((SELECT distinct ',' + QUOTENAME(convert(nvarchar(20),c._Date, 101))
FROM MIS_BM_Calendar c
where c._Date between @fromdate and @todate and _Day not in
('Sunday')
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
,1,1,'')
set @query= 'select UserName, '+@cols+' from
(select e.UserName, c._Date , (SUM(DATEDIFF(SS,0,c.TimeTaken))) As TimeTaken
from MIS_BM_Users e
inner join MIS_Opus c
on e.EmpId=c.EmpId
where (e.AccountManagerID='''+@empid+''') and c.Category not in ('''+@dt+''','''+@dt1+''')
group by c._Date, e.UserName
) As SourceTable
Pivot
(
SUM(TimeTaken) for _Date in ('+@cols+')
) As Pvt'
execute(@query)