Du kan gøre dette ved at bruge lag()
i SQL Server 2012+. I SQL Server 2008 vil jeg anbefale 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;