Решение математической задачи одним SQL-запросом
select n1,n2,left(time,8)
from
(
select trip_noV1 n1,trip_noV2 n2, convert(char(50) ,dateadd(s,sec,t_poz),114) time
from
(
select*,round( cast (((1-del_T/del_t_ran)*del_ta*del_tb)/(del_ta+del_tb)as numeric(10,3)),0) sec
from
(
select*,
case
when time_outV2time_outV1 then time_outV2
else time_outV2
end t_poz, --время позднего самолета
case
when time_outV2