求教sql语句两个日期、时间字段相减得到天数小时分秒的问题
selectrequestid,userid,workflowid,receivedate,receivetime,operatedate,operatetimefrom...
select requestid,userid,workflowid,receivedate,receivetime,operatedate,operatetimefrom workflow_currentoperator where workflowid=297 and requestid=110215 order by receivedate,receivetime如下图,通过上述语句查询处结果;希望得到字段:operatedate,operatetime;减去字段receivedate,receivetime;得到一个天数小时分秒的结果。 请教下语句怎么写?
展开
1个回答
展开全部
select requestid,userid,workflowid,receivedate,receivetime,operatedate,operatetime,
cast(day as varchar)+'天'+cast((hour-day*24) as varchar)+'小时'+
cast((minute-hour*60) as varchar)+'分'+
cast((second-minute*60) as varchar)+'秒' result
from(
select requestid,userid,workflowid,receivedate,receivetime,operatedate,operatetime,
datediff(d, CONVERT(datetime,receivedate+' '+receivetime,20),
CONVERT(datetime,operatedate+' '+operatetime,20)) day,
datediff(hh, CONVERT(datetime,receivedate+' '+receivetime,20),
CONVERT(datetime,operatedate+' '+operatetime,20)) hour,
datediff(n, CONVERT(datetime,receivedate+' '+receivetime,20),
CONVERT(datetime,operatedate+' '+operatetime,20)) minute,
datediff(s, CONVERT(datetime,receivedate+' '+receivetime,20),
CONVERT(datetime,operatedate+' '+operatetime,20)) second
from workflow_currentoperator
where workflowid=297 and requestid=110215
) t
order by receivedate,receivetime
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询