How can we get two lines before and after for a given identifier in a table?

advertisements

I have a table with 10 rows

id  values
 1    a
 2    b
 3    c
 4    d
 5    e
 6    f
 7    g
 8    h
 9    i
 10   j

I want to get two rows before and two rows after for @id = 5.

How can get?


Edit This should work as expected (hopefully):

select id, value
from [table]
where id-@id >= -2
AND   id-@id <=  2
AND   id-@id <>  0

Here's the running sql: http://sqlfiddle.com/#!6/ca4e5/3/0