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 は別として、応答時間は開始時間と同じ時間に入れられるということです。また、変更によって開始時刻よりも早くなる 2 行目のようなエッジ ケースも修正されます。