Du kan göra detta med lag()
i SQL Server 2012+. I SQL Server 2008 skulle jag rekommendera en 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;