Something slightly different. take your pick:create table #dts (dt datetime)goinsert #dts (dt)select getdate() dt union allselect dateadd(day,1,getdate()) union allselect dateadd(day,3,getdate()) union allselect dateadd(day,8,getdate()) union allselect dateadd(day,-1,getdate()) select max(datediff(minute, dt, nextdt)) maxDurationMinutesfrom ( select dt ,nextdt = (select min(dt) from #dts where dt > a.dt) from #dts a ) awhere nextdt is not nullgodrop table #dts
Be One with the OptimizerTG