ни как не могу разобраться вот в этом куске запроса:
insert into @temp
select [Idchain], [suc], [unsuc],
[int]
from (
select distinct [Idchain],
[suc] = case
when exists (select *
from @temp1 tt2
where tt2.idchain = tt1.idchain
and ([CallResult] = 5 or [CallResult] = 18)) then 1
else null
end,
[unsuc] = case @slist
when 1 then
case
when not exists (select *
from @temp1 tt2
where tt2.idchain = tt1.idchain
and ([CallResult] = 5 or [CallResult] = 18)) then 1
else null
end
when 2 then
case
when not exists (select *
from @temp1 tt2
where tt2.idchain = tt1.idchain
and ([CallResult] = 5 or [CallResult] = 18 or lenqueue <= @xline)) then 1
else null
end
end,
[int] = case
when
Interval = 1 then cast(floor(cast (datetimestart as float)) as datetime)
when
Interval = 7 then cast(floor(cast (datetimestart as float) - datepart (dw, datetimestart) + 1) as datetime)
when
Interval = 12 then cast (cast(datepart (yy, datetimestart) as nvarchar (4)) + '-' + cast(datepart (mm, datetimestart) as nvarchar (2)) + '-01' as datetime)
else
cast(
( floor( cast(datetimestart as float) * @mnog) / @mnog -
floor(cast(datetimestart as float)) )
as datetime)
end
from @temp1 tt1
) tb1
не понимаю что означает(tt1) вот тут : select *
from @temp1 tt2
where tt2.idchain = tt1.idchain
или тут: select *
from @temp1 tt2
where tt2.idchain = tt1.idchain