Możesz to zrobić za pomocą lag()
w SQL Server 2012+. W SQL Server 2008 polecam join
:
select s.*,
(case when s.start between s2.start and s2.end then 1 else 0 end) as flg
from sample s left outer join
sample sprev
on s.id = sprev.id + 1;