是一个关于工单的剩余时间的sql语句比如工单状态有A,B,C三种,也就是先从A到B,再从B到C,A状态到B状态的时间限制是5个工作日(星期六和星期日不算),B状态到C状态的时间限制是5个工作日(星期六和星期日不算)OrderInfo(工单表)
Id DealTime(工单处理时间) OrderStateId(工单状态ID)
001 2013-05-28 14:03:00 2
002 2013-05-27 10:30:00 1
003 2013-05-20 10:30:00 1
004 2013-05-17 17:30:00 2
OrderStateInfo(工单状态表)
OrderStateId OrderStateName
1 A
2 B
3 C我想要这样一个效果
OrderId Timeout(超时多少(小时:分钟)) TimeoutFLag(是否超时) DealTime(工单处理时间)
001 没超时 2013-05-28 14:03:00
002 没超时 2013-05-27 10:30:00
003 超时 2013-05-20 10:30:00
请问这句sql语句应该怎么写?
Id DealTime(工单处理时间) OrderStateId(工单状态ID)
001 2013-05-28 14:03:00 2
002 2013-05-27 10:30:00 1
003 2013-05-20 10:30:00 1
004 2013-05-17 17:30:00 2
OrderStateInfo(工单状态表)
OrderStateId OrderStateName
1 A
2 B
3 C我想要这样一个效果
OrderId Timeout(超时多少(小时:分钟)) TimeoutFLag(是否超时) DealTime(工单处理时间)
001 没超时 2013-05-28 14:03:00
002 没超时 2013-05-27 10:30:00
003 超时 2013-05-20 10:30:00
请问这句sql语句应该怎么写?
Id varchar(10),
DealTime datetime,
OrderStateId int
)
insert @OrderInfo
select '001','2013-05-28 14:03:00',2
union all select '002','2013-05-27 10:30:00',1
union all select '003','2013-05-20 10:30:00',1
union all select '004','2013-05-17 17:30:00',2--5个工作日+双休日 = 7天
select id,
case when Tio>0 then cast(Tios/3600 as varchar(10))+':'+
cast(Tios % 60 as varchar(10))else '0:0' end TimeoutFLag,
case when Tio>0 then '超时' else '没超时' end TimeoutFLag,
DealTime from(
select id,datediff(ss,DealTime,getdate())-(86400*7*OrderStateId) Tios,
datediff(ss,DealTime,getdate())/(86400*7*OrderStateId) Tio,DealTime
from @OrderInfo)t
Id varchar(10),
DealTime datetime,
OrderStateId int
)
insert @OrderInfo
select '001','2013-05-28 14:03:00',2
union all select '002','2013-05-27 10:30:00',1
union all select '003','2013-05-20 10:30:00',1
union all select '004','2013-05-17 17:30:00',2--5个工作日+双休日 = 7天
select id,
case when Tio>0 then cast(Tios/3600 as varchar(10))+':'+
cast((Tios % 3600)/60 as varchar(10))else '0:0' end TimeoutFLag,
case when Tio>0 then '超时' else '没超时' end TimeoutFLag,
DealTime from(
select id,datediff(ss,DealTime,getdate())-(86400*7*OrderStateId) Tios,
datediff(ss,DealTime,getdate())/(86400*7*OrderStateId) Tio,DealTime
from @OrderInfo)t
通过你的sql语句最后得出的结果中,为何OrderId为004的工单没超时呢?
OrderID为004的工单应该已经超时了啊,而且在最后列出的数据表格中,数据列 Timeout(超时多少(小时:分钟)) 最好也能显示相应的超时数据,没超时的能用-(小时:分钟)显示,已经超时的能用+(小时:分钟)来显示
关于负数时分,LZ自己改一下嘛,又不难,我现在用PAD没法改,呵呵
是这样的,A状态到B状态的时间限制是5个工作日,B状态到C状态的时间限制是5个工作日,但是工单状态一旦变成B状态后,时间限制清零,重新开始计时,并且工单状态在达到C状态的时间限制是5个工作日