2

如何将表示分钟的int值(即:)转换为如下所示的值:()。1800dd:hh:mmdays:hours:minutes

所以1800应该转换成1:06:001 day 6 hours 0 minutes)。

在存储过程中,我有这个:

SELECT 
    Record_ID, Project_ID, Ticket_ID, WO_Type, DC, Title, Device_Quantity, 
    Total/1440 as Total,  
    ((Total - Elapsed) - DATEDIFF(mi, Record_Time, getdate())) as FinalTimeLeft, 
    Completed 
FROM Record

我将如何将转换实施到 SP 中?多于FinalTimeLeft=1800

4

1 回答 1

5

这个例子怎么样 - 它有小时,分钟和秒,但它应该很容易修改天,小时和分钟:

SELECT 
  CAST(mins / 3600 AS VARCHAR) + ':' + 
  RIGHT('0' + CAST((mins % 3600) / 60  AS VARCHAR), 2) + ':' +
  RIGHT('0' + CAST(mins % 60 AS VARCHAR), 2)
FROM 
  (SELECT 1800 AS mins) a

编辑:包括您的存储过程和我的代码修改为天,小时和分钟:

SELECT 
  *
  ,CAST(FinalTimeLeft / 1440 AS VARCHAR) + ':' +
     RIGHT('0' + CAST((FinalTimeLeft / 60) % 24 AS VARCHAR), 2) + ':' +
     RIGHT('0' + CAST(FinalTimeLeft % 60 AS VARCHAR), 2) AS duration
FROM ( 
SELECT 
  Record_ID
  ,Project_ID
  ,Ticket_ID
  ,WO_Type
  ,DC
  ,Title
  ,Device_Quantity
  ,Total/1440 as Total
  ,((Total-Elapsed)-DATEDIFF(mi,Record_Time,getdate())) as FinalTimeLeft
  ,Completed
FROM record) a
于 2013-03-12T15:22:43.610 回答