create table #A ([id] int, title varchar(50), counter int)
insert into #A select 1, 'aaa', 2
insert into #A select 2, 'bbb', 2
insert into #A select 3, 'ccc', 3
insert into #A select 4, 'ccc', 4
insert into #A select 5, 'ccc', 5
insert into #A select 6, 'ccc', 6
insert into #A select 7, 'ccc', 8
if exists(select [id] from #A where [id] = 5)
Begin
select * from (
select top 1 * from #A where [id] < 5 order by [id] desc ) a
UNION ALL
select top 1 * from #A where [id] > 5
End
select * from
(
select top 1 * from @t where id<3 order by id desc
) a
[union] all /*-----------去掉[]号---*/
select * from
(
select top 1 * from @t where id>3
) b
id title counter
----------- -------------------- -----------
2 bbb 2
4 ddd 2