Get the distance from the given number by subtracting and using the abs
function:
select top 4 Number
from NumberTable
where number <> 1009
order by abs(Number - 1009)
Edit:
As you now mention that you have a very large table, you would need a way to elliminate most of the results first. You could pick the four closest in both direction and then get the correct ones from that:
select top 4 Number
from (
select Number
from (
select top 4 Number
from NumberTable
where number < 1009
order by number desc
)
union all
select Number
from (
select top 4 Number
from NumberTable
where number > 1009
order by number
)
)
order by abs(Number - 1009)
If the numbers are evenly distributed so that you are sure that you can find the numbers in a range like for example +-100 numbers, you can simply get that range first:
select top 4 Number
from (
select Number
from NumberTable
where number between 1009-100 and 1009+100
)
where number <> 1009
order by abs(Number - 1009)