|
create table #temp
(id varchar (50)
)
insert into #temp
select '1' union all select '2' union all select '3' union all select '4' union all select '5' union all select '6' union all select '7' union all select '8'
select * from #temp
----------------------
id
1
2
3
4
5
6
7
8
Two digits before and after query
select * from #temp
where
[id] in (select distinct top 2 [id] from #temp where [id] <5 order by [id] DESC)
or
[id] = 5
or
[id] in (select distinct top 2 [id] from #temp where [id]> 5 order by [id] ASC)
-------------
id
3
4
5
6
7 |
|