RuslanSharipov,
declare @A1 table (id int identity primary key, tm time);
insert @A1 (tm) values ('13:08:21'),('13:14:07');
declare @B1 table (id int identity primary key, tm time);
insert @B1 (tm) values ('13:08:21'),('13:10:38'),('13:13:35');
declare @C1 table (id int identity primary key, tm time);
insert @C1 (tm) values ('13:08:21'),('13:12:25');
select row_number()over(order by (select 1))npp
, *
, max(iif(typ='a',tm,null))over(order by tm,typ)a
, max(iif(typ='b',tm,null))over(order by tm,typ)b
, max(iif(typ='c',tm,null))over(order by tm,typ)c
from (
select 'a' typ, tm from @A1
union all
select 'b' typ, tm from @B1
union all
select 'c' typ, tm from @C1
)u
order by u.tm, u.typ
npp | typ | tm | a | b | c | 1 | a | 13:08:21.000 | 13:08:21.000 | NULL | NULL | 2 | b | 13:08:21.000 | 13:08:21.000 | 13:08:21.000 | NULL | 3 | c | 13:08:21.000 | 13:08:21.000 | 13:08:21.000 | 13:08:21.000 | 4 | b | 13:10:38.000 | 13:08:21.000 | 13:10:38.000 | 13:08:21.000 | 5 | c | 13:12:25.000 | 13:08:21.000 | 13:10:38.000 | 13:12:25.000 | 6 | b | 13:13:35.000 | 13:08:21.000 | 13:13:35.000 | 13:12:25.000 | 7 | a | 13:14:07.000 | 13:14:07.000 | 13:13:35.000 | 13:12:25.000 |
|