create table #t(id int identity(1,1),num int)
insert into #t(num)
select 10
union all select 11
union all select 22
union all select 23
union all select 41
union all select 44
select T1.id
from
(select * from #t where id%2>0) T1,
(select * from #t where id%2=0) T2
where T1.id=T2.id-1
and T2.num-T1.num <=3
create table #t(id int identity(1,1),num int)
insert into #t(num)
select 10
union all select 11
union all select 22
union all select 23
union all select 41
union all select 44
select * from #t as a
where exists(select * from #t where (num-a.num) between 1 and 3)
create table #t(id int identity(1,1),num int)
insert into #t(num)
select 10
union all select 11
union all select 22
union all select 23
union all select 41
union all select 44
select * into #t2 from #t
select #t.*
from #t,#t2
where #t.id=#t2.id and ((select num from #t2 where #t.id=#t2.id+1) -#t.num)<3
declare #t table (id int identity(1,1),num int)
insert into #t(num)
select 10
union all select 11
union all select 22
union all select 23
union all select 41
union all select 44
select * into #t2 from #t
select #t.*
from #t,#t2
where #t.id=#t2.id and ((select num from #t2 where #t.id=#t2.id+1) -#t.num)<3
declare @t table (id int identity(1,1),num int)
insert into @t(num)
select 10
union all select 11
union all select 22
union all select 23
union all select 41
union all select 44
select * from @t
select * from @t as a
where exists(select * from @t where (num-a.num) between 1 and 3)
create table #t(id int identity(1,1),num int)
insert into #t(num)
select 10
union all select 11
union all select 22
union all select 23
union all select 41
union all select 44
select * from #t as a
where exists(select * from #t where abs(num-a.num) between 1 and 3)