declare @t table (
Starttime datetime,
Answertime datetime);
insert @t values (
'2012-08-30 00:40:40.000','2012-08-30 03:40:53.000'),(
'2012-08-30 00:59:59.900','2012-08-30 03:00:03.000');
update @t set Answertime =
case when dateadd(hh,datediff(hh,answertime,starttime),answertime) > starttime
then dateadd(hh,datediff(hh,answertime,starttime),answertime)
else dateadd(hh,datediff(hh,answertime,starttime)+1,answertime) end
where Answertime > DateAdd(hh,1,StartTime); -- more than 1 hour apart
select * from @T;
>>
STARTTIME ANSWERTIME
August, 30 2012 00:40:40 August, 30 2012 00:40:53
August, 30 2012 00:59:59 August, 30 2012 01:00:03
答案的要点是将 Minutes:Seconds.MilliSecs 放在一边,应答时间与开始时间相同。它还修复了第二行等边缘情况,其中更改使其早于开始时间。